0

Here is the VBA code which I used to copy Excel range & paste it as picture in Outlook Email body. It used to work for me, but recently when I tried it after long gap of 1 year, I can see that macro is terminating on this line "doc.Range.PasteAndFormat wdChartPicture" without any error message.

Please help in identifying the issue.

Sub CopyExcelRangeToOutlookMail()

        
        Dim outlookApplication As Outlook.Application
        Dim mail As Outlook.MailItem
        Dim insp As Outlook.Inspector
        Dim doc As Word.Document
        Dim msgText As String
        Dim myCell1 As Range
        Dim To_List As String
        Dim myCell2 As Range
        Dim CC_List As String
        Dim myCell3 As Range
        Dim BCC_List As String
        
        Set outlookApplication = New Outlook.Application
        Set mail = outlookApplication.CreateItem(olMailItem)
        
            With mail
                     .BodyFormat = olFormatRichText
                     .Display
                     .To = To_List
                     .CC = CC_List
                     .BCC = BCC_List
                     .Subject = "Team wishes you Happy Birthday!"
                     Set insp = .GetInspector
                     Set doc = insp.WordEditor
                     
                    doc.Range.InsertBefore msgText
                    Sheet2.Range("A7:S51").Copy
                     
                    DoEvents
                    doc.Range.PasteAndFormat wdChartPicture    'macro terminating while trying to execute this line without error or result

                    Application.CutCopyMode = False
            End With

End Sub
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Puntal
  • 118
  • 8

0 Answers0