Below is some code I found and made some adjustments to. I would appreciate any thoughts to help me insert some bolded words into my e-mail text.
Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
Declare Function ShowWindow& Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long)
Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Function CreateNotesSession&()
Const notesclass$ = "NOTES"
' "Neues Memo - Lotus Notes"
Const SW_SHOWMAXIMIZED = 3
Dim Lotus_Session As Object
Dim rc&
Dim lotusWindow&
Set Lotus_Session = CreateObject("Notes.NotesSession")
DoEvents
DoEvents
lotusWindow = FindWindow(notesclass, vbNullString)
If lotusWindow <> 0 Then
rc = ShowWindow(lotusWindow, SW_SHOWMAXIMIZED)
rc = SetForegroundWindow(lotusWindow)
CreateNotesSession& = True
Else
CreateNotesSession& = False
End If
End Function
Sub CreateMailandAttachFileAdr(Optional IsSubject As String = "", Optional SendToAdr As String, Optional CCToAdr As String, Optional BCCToAdr As String = "", Optional Attach1 As String = "")
On Error GoTo Err_Routine
Const EMBED_ATTACHMENT As Integer = 1454
Const EMBED_OBJECT As Integer = 1453
Const EMBED_OBJECTLINK As Integer = 1452
Dim s As Object ' use back end classes to obtain mail database name
Dim db As Object '
Dim Doc As Object ' front end document
Dim beDoc As Object ' back end document
Dim workspace As Object ' use front end classes to display to user
Dim bodypart As Object '
Dim strWording As String
Call CreateNotesSession&
Set s = CreateObject("Notes.Notessession") 'create notes session
Set db = s.GetDatabase("", "") 'set db to database not yet named
Call db.OPENMAIL ' set database to default mail database
Set beDoc = db.CreateDocument
Set bodypart = beDoc.CreateRichTextItem("Body")
' Filling the fields
'###################
beDoc.Subject = IsSubject
beDoc.SendTo = SendToAdr
beDoc.CopyTo = CCToAdr
beDoc.BlindCopyTo = BCCToAdr
' Attaches I
'###########
If Len(Attach1) > 0 Then
If Len(Dir(Attach1)) > 0 Then
Call bodypart.EmbedObject(EMBED_ATTACHMENT, "", Attach1, Dir(Attach1))
End If
End If
Set workspace = CreateObject("Notes.NotesUIWorkspace")
' Positioning Cursor
'###################
'Call workspace.EDITDOCUMENT(True, beDoc).GOTOFIELD("Body")
strWording = "Here is some text I want to add” ‘But I want the word ‘text’ to be bold
Call workspace.EDITDOCUMENT(True, beDoc).FIELDSETTEXT("Body", vbCrLf & strWording & vbCrLf & vbCrLf)
Set s = Nothing
Set db = Nothing
Set beDoc = Nothing
Set bodypart = Nothing
Exit Sub
Err_Routine:
Select Case Err.Number
Case 424
Resume Next
Case Else
MsgBox Err.Number & vbCrLf & Err.Description
End Select
End Sub
Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
Declare Function ShowWindow& Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long)
Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Function CreateNotesSession&()
Const notesclass$ = "NOTES"
' "Neues Memo - Lotus Notes"
Const SW_SHOWMAXIMIZED = 3
Dim Lotus_Session As Object
Dim rc&
Dim lotusWindow&
Set Lotus_Session = CreateObject("Notes.NotesSession")
DoEvents
DoEvents
lotusWindow = FindWindow(notesclass, vbNullString)
If lotusWindow <> 0 Then
rc = ShowWindow(lotusWindow, SW_SHOWMAXIMIZED)
rc = SetForegroundWindow(lotusWindow)
CreateNotesSession& = True
Else
CreateNotesSession& = False
End If
End Function
Sub CreateMailandAttachFileAdr(Optional IsSubject As String = "", Optional SendToAdr As String, Optional CCToAdr As String, Optional BCCToAdr As String = "", Optional Attach1 As String = "")
On Error GoTo Err_Routine
Const EMBED_ATTACHMENT As Integer = 1454
Const EMBED_OBJECT As Integer = 1453
Const EMBED_OBJECTLINK As Integer = 1452
Dim s As Object ' use back end classes to obtain mail database name
Dim db As Object '
Dim Doc As Object ' front end document
Dim beDoc As Object ' back end document
Dim workspace As Object ' use front end classes to display to user
Dim bodypart As Object '
Dim strWording As String
Call CreateNotesSession&
Set s = CreateObject("Notes.Notessession") 'create notes session
Set db = s.GetDatabase("", "") 'set db to database not yet named
Call db.OPENMAIL ' set database to default mail database
Set beDoc = db.CreateDocument
Set bodypart = beDoc.CreateRichTextItem("Body")
' Filling the fields
'###################
beDoc.Subject = IsSubject
beDoc.SendTo = SendToAdr
beDoc.CopyTo = CCToAdr
beDoc.BlindCopyTo = BCCToAdr
' Attaches I
'###########
If Len(Attach1) > 0 Then
If Len(Dir(Attach1)) > 0 Then
Call bodypart.EmbedObject(EMBED_ATTACHMENT, "", Attach1, Dir(Attach1))
End If
End If
Set workspace = CreateObject("Notes.NotesUIWorkspace")
' Positioning Cursor
'###################
'Call workspace.EDITDOCUMENT(True, beDoc).GOTOFIELD("Body")
strWording = "Here is some text I want to add” ‘But I want the word ‘text’ to be bold
Call workspace.EDITDOCUMENT(True, beDoc).FIELDSETTEXT("Body", vbCrLf & strWording & vbCrLf & vbCrLf)
Set s = Nothing
Set db = Nothing
Set beDoc = Nothing
Set bodypart = Nothing
Exit Sub
Err_Routine:
Select Case Err.Number
Case 424
Resume Next
Case Else
MsgBox Err.Number & vbCrLf & Err.Description
End Select
End Sub