0
votes
    Dim objOutlook As Object
    Dim objMail As Object
    Set objOutlook = CreateObject("Outlook.Application")
    Set objMail = objOutlook.CreateItem(0)

   With objMail
   .To = "a22550@stuart.iit.edu"
   .Subject = "Report of Fixed Income" & Format(Now() - 1, "mmmm dd,yyyy")
   .Body = "Dear Sir" & vbNewLine & Format(Now() - 1, "mmmm dd,yyyy") & 
   "Please regard the following tables:" & vbNewLine &
    "Thank you!"
   .Attachments.Add "C:\Users\008425\Desktop\Fixed Income--2020.05.13.xlsm

 'word Editor
   Dim wdDoc As Object     '## Word.Document
    Dim wdRange As Object   '## Word.Range
   Set wdDoc = objMail.GetInspector.WordEditor
  wdDoc.Application.Selection.Start = Len(.Body)

I tried to Copy my excel range to Outlook mail with the my greeting description in the beginning and come next my excel copy range as a picture...After I run this syntax, my greeting skip to the end of the mail body just like signature..

Does anyone know hot to set sequences greetings→ paste charts→signatures from start to end in the outlook mail body by VBA? [ wdDoc.Application.Selection.Start = Len(.Body)] is not right

1

1 Answers

0
votes
Private Sub test()

    Dim objOutlook As Object
    Dim objMail As Object
    
    Set objOutlook = CreateObject("Outlook.Application")
    Set objMail = objOutlook.CreateItem(0)
    
    Dim defSignature As String

    With objMail
        
        .Display    ' Bring the signature to the body
        defSignature = objMail.Body ' Save the signature
        
        ' Replace the body
        .Body = "Dear Sir" & vbNewLine & Format(Now() - 1, "mmmm dd,yyyy") & _
          "Please regard the following tables:" & vbNewLine & vbNewLine
        
        '.Attachments.Add "C:\Users\008425\Desktop\Fixed Income--2020.05.13.xlsm"
        
        'word Editor
        Dim wdDoc As Object     '## Word.Document
        Dim wdRange As Object   '## Word.Range
        Set wdDoc = objMail.GetInspector.WordEditor
        
        ' Move the cursor to the end of the body
        wdDoc.Application.Selection.EndKey Unit:=wdStory, Extend:=wdMove
        
        ' Insert after the cursor
        wdDoc.Application.Selection.InsertAfter "This should be inserted after current body."
        
        objMail.Body = objMail.Body & vbNewLine & "Thank you!" & defSignature
            
    End With
    
End Sub