'Issue with worksheet object and LoadPicture in VBA
I have been working on an excel macro and have come across an issue that doesn't make sense to me.
I have on two of my sheets, (Sheets("Printing Sheet")
and Sheets("Printing Sheet B")
, an Xactive image object called slipLogo. I created a subProcedure that should change the image loaded into slipLogo and the color of other cells on the sheet depending on an options selected within a userform. The userfrom also decides which of the two slipLogos and therefore sheets are being changed. But I was having problems with the image changing portion, so I pulled out the troublesome code to do some troubleshooting on it and focused on just one of the two sheets.
The issue is that I get the error "method failing" which points to the slipLogo part of ws.slipLogo.Picture=LoadPicture(C:Users\Logo.jpg)
. However when I use instead the following line Sheets("Printing Sheet").slipLogo.Picture=LoadPicture("C:\Users\Logo.jpg")
everything works.
This indicates to me that for some reason ws
does not equal Sheets("Printing Sheet")
.
Sub Help5()
Dim ws As Worksheet
Set ws = Sheets("Printing Sheet")
Dim imagePath As String
imagePath = "C:\Users\Logo.jpg"
ws.slipLogo.Picture = LoadPicture(imagePath)
'Sheets("Printing Sheet").slipLogo.Picture = LoadPicture(imagePath)
With Sheets("Printing Sheet").slipLogo 'the ws also does not work at this location
.Height = 35
End With
End Sub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|