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:

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
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.
 
Upvote 0

Forum statistics

Threads
1,223,981
Messages
6,175,767
Members
452,668
Latest member
mrider123

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top