Reputation: 1
I know people have asked this question before but I can't find a straightforward answer on how to fix this. I'm trying to automate the process of taking screenshots of some of my sheets within a defined range and sending them to my email. I keep getting this error on one of my lines in the code ('strRng.CopyPicture xlScreen, xlPicture'). Can someone please help me with a solution to this?
Sub range_to_image(shtname, FileName As String)
Application.Run "RefreshAllWorkbooks"
Application.Run "RefreshAllStaticData"
Sheets(shtname).Activate
Application.Wait (Now + TimeValue("0:00:10"))
Dim strRng As Range
Set strRng = Range(Range("start"), Range("end"))
Application.CutCopyMode = False
strRng.Copy
strRng.CopyPicture xlScreen, xlPicture
lWidth = strRng.Width
lHeight = strRng.Height
Set Cht = ActiveSheet.ChartObjects.Add(Left:=0, Top:=0, Width:=lWidth, Height:=lHeight)
Cht.Activate
Application.Wait (Now + TimeValue("0:00:10"))
With Cht.Chart
.Paste
.Export FileName:=Application.ThisWorkbook.Path & "\Pictures\" & FileName & "-" & shtname &
".jpg", Filtername:="JPG"
End With
Cht.Delete
End Sub
Upvotes: 0
Views: 222
Reputation: 21
CopyPicture method of range class failed - sometimes
The answer is here.
Upvotes: 1