Reputation: 699
I have problem with excel macro which copies range of cells and store them as a picture on shared drive. Problem started I dont know when but it worked nice and suddenly it wont copy the range.
The whole process is like this. I have application in C#, it opens two Excels and runs three macros. That works fine, but last macro started showing errors.
Code below:
Sub red_current_status()
Dim sSheetName As String
Dim oRangeToCopy As Range
Dim oCht As Chart
Application.CutCopyMode = False
Application.ScreenUpdating = True
Application.WindowState = xlMaximized
Worksheets("Charts").Range("A1:E15").CopyPicture xlScreen, xlBitmap
Set oCht = Charts.Add
With oCht
.Paste
.Export Filename:="X:\path\image.gif", Filtername:="GIF"
End With
End Sub
Which shows error:
"Method CopyPicture of object Range Failed"
What I tried and googled:
Any help will be appreciated.
Upvotes: 2
Views: 2686
Reputation: 43585
If you do not specify the Workbook, it takes the ActiveWorkbook
. The same goes with the Worksheet - if you do not specify it, it takes the ActiveSheet
. Thus use the following:
ThisWorkbook.Worksheets(1).Range("A1:E15").CopyPicture 1,2
Upvotes: 2