Reputation: 1115
I've looked far and wide for examples of the Shapes.AddPicture method, and it seems that the following code should work:
Sub TestAddPicture()
Call ActiveSheet.Shapes.AddPicture( _
"C:\Full\Path\To\BarsBoxes.png", _
False, True, 1, 1, -1, -1)
End Sub
This generates a runtime error 1004. If I remove the Call
, it doesn't compile. I tried replacing False
and True
with msoFalse
and msoTrue
, but it doesn't solve the problem. I also tried using 0 and 1 in place of False
and True
, again to no avail.
Thanks for suggestions on where the error may lie. I am using Excel 2013 desktop app.
Afternote:
The same error occurs when assigning the result of AddPictures to a variable:
Sub TestAddPicture()
Dim s As Shape
Set s = ActiveSheet.Shapes.AddPicture( _
"C:\Full\Path\To\BarsBoxes.png", _
False, True, 1, 1, -1, -1)
End Sub
Upvotes: 0
Views: 571
Reputation: 1115
At least in this case, the problem turned out to be a display option for the workbook:
File -> Options -> Advanced
-> Display options for this workbook
-> For objects, show: (choices are "All" or "Nothing")
The above setting was set at "Nothing". Changing it to "All" seemed to enable Insert-Pictures.
The funny thing is that I bashed my head against this just recently and posted the solution here. I got the solution from here
Upvotes: 1