VBA created Image displays as blank after execution

manicmighty

New Member
Joined
Apr 18, 2018
Messages
15
I have used the below VB code to copy a range from my excel sheet to create an image file which I then add to the body of an email:

Once the file has been created it then sometimes displays the image but more often than not it comes back as blank showing just a border; can anyone advise on how to amend the code to ensure the image is displayed each time I run the report.

Thanks

Sub CreateEmailImageEOD()

Selection.CopyPicture xlScreen, xlBitmap
Dim mchart As ChartObject
Set mchart = Sheets("Report_ENDOFDAY").ChartObjects.Add(0, 2500, 50, 50)
Sheets("Report_ENDOFDAY").Select
Range("B2:AB35").Select
mchart.Name = "EOD"
mchart.Width = Selection.Width
mchart.Height = Selection.Height
Sheets("Report_ENDOFDAY").ChartObjects("EOD").Activate
ActiveChart.Paste
ActiveChart.Export ThisWorkbook.Path & "EOD.bmp", "bmp"
mchart.Delete

End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
First, I'm assuming that you want the width and height of your image the same size as your selected range of cells. Secondly, it looks like you're missing a backslash (\) from your destination path and filename. Accordingly, try the following instead...

Code:
Option Explicit

Sub CreateEmailImageEOD()


    Selection.CopyPicture xlScreen, xlBitmap
    
    Dim chrtObj As ChartObject
    With Selection
        Set chrtObj = ActiveSheet.ChartObjects.Add(0, 0, .Width, .Height)
    End With
    
    With chrtObj
        .Activate
        .Name = "EOD"
        With .Chart
            .ChartArea.Format.Line.Visible = msoFalse
            .Paste
            .Export ThisWorkbook.Path & "\EOD.bmp", "bmp"
        End With
        .Delete
    End With
    
End Sub

Does this help?
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,217
Members
452,619
Latest member
Shiv1198

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