Mail Macro works in step through, not at full speed... Worked as-is in '13 but not in '16

burns14hs

Board Regular
Joined
Aug 4, 2014
Messages
76
Hello All -

The following macro works if I step through it but if I just execute it in normal mode it mails a blank picture instead of the actual picture. I'm not that familiar with the code itself and am just managing a workbook that was left to me at work. The code worked fine as is in 2013, but we just upgraded to 2016 and it no longer works. The problem appears to be in the bolded section - beginning Set co = . When stepping through, this is where the picture is filled in. Any help on what the issue is, why it worked in 2013 but not in 2016, or how to fix it would be much appreciated.

Code:
Sub DPPEmail()
    
        
    Application.EnableEvents = False
    Application.ScreenUpdating = False
    Call UnProtectAll
    Application.ScreenUpdating = True
    '===================================================
    ' Export Range as PNG file
    '===================================================
    '''' Set Range you want to export to file
    Dim r As Range
    Dim co As ChartObject
    Dim picFile As String
    Dim sCellVal As String
    Dim sTo As String
    Dim sTo2 As String
    Dim emailRng As Range
    Dim cl As Range
    
    Sheets("Daily Plan").Select
    
    Set EmailTo = Worksheets("Daily Plan").Range("O6:O12")
    For Each cl In EmailTo
        If cl.Value <> "" Then sTo = sTo & cl.Value & "; "
    Next
    
    Set r = Worksheets("Daily Plan").Range("A1:K21")

    ''' Copy range as picture onto Clipboard
    r.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
    picFile = Environ("Temp") & "\TempExportChart.png"
    
    ''' Create an empty chart with exact size of range copied
[B]    Set co = r.Parent.ChartObjects.Add(Left:=r.Left, Top:=r.Top, Width:=r.Width, Height:=r.Height)
    With co[/B]
        ''' Paste into chart area, export to file, delete chart.
        .Chart.Paste
        .Chart.Export picFile
        .Delete
    End With
    

    '===================================================
    ' Create Email and Import Picture
    '===================================================
    'send out the email
    Dim OutApp As Object
    Set OutApp = CreateObject("Outlook.Application")
    Dim OutMail As Object
    Set OutMail = OutApp.CreateItem(olMailItem)
    Dim signature As String
    Dim strBody As String
        
    ' Subject location
    OutMail.Display
    signature = OutMail.HTMLBody
    
    strBody = "******>[IMG]https://www.mrexcel.com/forum/newthread.php?do=postthread&f=10[/IMG]"
    
    On Error Resume Next
    With OutMail
        .To = sTo
        .CC = sTo2
        .BCC = ""
        .Subject = "SDF6 IB " & Worksheets("Daily Plan").Range("b8")
        .HTMLBody = strBody & vbNewLine & signature
        .Attachments
        .Send
    End With
    Kill picFile
    On Error GoTo 0
    
    'Tidy Up
    Set OutMail = Nothing
    Set OutApp = Nothing
    Set co = Nothing
    Set r = Nothing

    Application.ScreenUpdating = False
    Call ProtectAll
    Application.ScreenUpdating = True
    Application.EnableEvents = True
    Call StopTimer
    Call StartTimer
    
    Sheets("Daily Plan").Select
    Range("A1").Select
    
    MsgBox "You have successfully emailed the plan!"
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,224,507
Messages
6,179,172
Members
452,893
Latest member
denay

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