Hello All,
The issue I am having is that my code works perfectly when I step through it in the VBA window but when I assign the same macro to a button and run it from the sheet it doesn't work properly.
I am copying a group and pasting it as a chart object for exporting as an image, but when I am running it off a button the image is blank. When I run each step in the VBA window it exports with the image in it properly.
My code is as follows:
Sub export_linear()
Dim myFileName As String
Dim fullpathandfilename As String
Dim mypath As String
Dim mygroup As Object
Dim chtObj As Object
Application.ScreenUpdating = False
mypath = ActiveWorkbook.path
Set mygroup = Worksheets("Linear_Gauge").Shapes("Group 17")
mygroup.CopyPicture
Set chtObj = ActiveSheet.ChartObjects.Add(mygroup.Left, mygroup.Top, mygroup.Width, mygroup.Height)
chtObj.Name = "Grouped 2"
chtObj.Chart.Paste
ActiveSheet.Shapes("Grouped 2").ScaleWidth 1.75, msoFalse, msoScaleFromTopLeft
ActiveSheet.Shapes("Grouped 2").ScaleHeight 1.75, msoFalse, msoScaleFromTopLeft
myTime = Format(TimeValue(Now), "hh.mm.ss am/pm")
myFileName = Range("O2").Value & " (" & myTime & ").png"
fullpathandfilename = ThisWorkbook.path & "\" & myFileName
On Error Resume Next
Kill (path)
chtObj.Chart.export Filename:=fullpathandfilename, Filtername:="PNG"
chtObj.Delete
Set chtObj = Nothing
Application.ScreenUpdating = True
End Sub
It seems to not be recognizing/performing the "chtObj.Chart.Paste" operation. I have attempted to add some wait operations in there in case it was running through lines faster than my computer could keep up, that's also why I have screenupdating = False.
Any help on how to resolve this issue would be greatly appreciated.
Thank you.
Bookmarks