Excel issue pasting in image into outlook

navrak

New Member
Joined
Oct 29, 2013
Messages
9
Hi all, my Microsoft Office 2016 recently installed some patches and my previous code no longer works :(

I created an email where I would paste a set print area in the Excxel into the body of an outlook email. Now when I run the code it says "Compile error: Sub or Function not defined" on the line that says "Call CreatePic". It just stopped working after the recent patching.

Any help will be much appreciated.

VBA Code:
Dim outMail As Object
    Dim d1 As Date, d2 As Date, wf As WorksheetFunction
    Set wf = Application.WorksheetFunction
    d1 = Date
    d2 = wf.WorkDay(d1, -1)
   
    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With

    Set OutApp = CreateObject("Outlook.Application")
    Set outMail = OutApp.CreateItem(0)
  
    On Error Resume Next
    With outMail
        .To = ""
        .CC = ""
        .BCC = ""
        .Subject = "Margin as of " & Format(d2, "mmmm dd, yyyy")
        .HTMLBody = "<span LANG=EN>" _
                & "<p class=style2><span LANG=EN><font FACE=Arial SIZE=2>" _
                & "Dear All,<br ><br >Please find below the margin level: " _
                & "<br><br>"

        Call createPic("DailyEmail", "MarginArea", "pnlImage")
       
       
        TempFilePath = Environ$("temp") & "\"
        .Attachments.Add TempFilePath & "pnlImage.png", olByValue, 0
       
        .HTMLBody = .HTMLBody & _
                "<img src='" & TempFilePath & "pnlImage.png'>" & _
                "<br><br><br>Best Regards,<br></font></span>" & "<span LANG=EN><font FACE=Arial SIZE=2>" & Application.UserName
                       
        .Display
       
    End With
   
    file = TempFilePath & "pnlImage.png"
    If FileExists(file) > 0 Then
        SetAttr file, vbNormal
        Kill file
    End If
   
    On Error GoTo 0

    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With

    Set outMail = Nothing
    Set OutApp = Nothing

End Sub
 
Last edited by a moderator:

Some videos you may like

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,403
You'll need to include the procedure called createPic. Also, make sure that you add it to either the same module as your existing code or to a regular/standard module.
 

Watch MrExcel Video

Forum statistics

Threads
1,118,766
Messages
5,574,124
Members
412,573
Latest member
Chriszion
Top