Sheet7 vs. decleared Sheet7 .image not working

MarkCBB

Active Member
Joined
Apr 12, 2010
Messages
497
Hi there,

I think i am losing my mind a bit, I get the following error "Complie error: Method or data member not found"

I am using the following code:
Code:
Sub AddPicture()
Dim MyPictureName1 As String
Dim MyPictureName2 As String
Dim MyPictureName3 As String
Dim SHT_LIST As Worksheet
Dim SHT_FilteredOutlet_DB As Worksheet
Dim SHT_Report5 As Worksheet
Dim i As Long
Set SHT_FilteredOutlet_DB = Sheet12
Set SHT_LIST = Sheet2
Set SHT_Report5 = Sheet7
i = SHT_LIST.Range("C11").Value
MyPictureName1 = SHT_FilteredOutlet_DB.Range("E4").Offset(i, 0).Value & " Front of store"
MyPictureName2 = SHT_FilteredOutlet_DB.Range("E4").Offset(i, 0).Value & " Inside of Store"
MyPictureName3 = SHT_FilteredOutlet_DB.Range("E4").Offset(i, 0).Value & " Nappies"
If Len(Dir("D:\testing\" & MyPictureName1 & ".png", vbDirectory)) < 0 Then MyPictureName1 = "HUGGIES"
If Len(Dir("D:\testing\" & MyPictureName1 & ".png", vbDirectory)) < 0 Then MyPictureName2 = "HUGGIES"
If Len(Dir("D:\testing\" & MyPictureName1 & ".png", vbDirectory)) < 0 Then MyPictureName3 = "HUGGIES"
SHT_Report5.Image1.Picture = LoadPicture("D:\testing\" & MyPictureName1 & ".png") ' DOES NOT WORK
Sheet7.Image1.Picture = LoadPicture("D:\testing\" & MyPictureName1 & ".png") ' WORKS FINE
End Sub

But this line give me the above error:
Code:
SHT_Report5.Image1.Picture = LoadPicture("D:\testing\" & MyPictureName1 & ".png") ' DOES NOT WORK

and this one works fine:
Code:
heet7.Image1.Picture = LoadPicture("D:\testing\" & MyPictureName1 & ".png") ' WORKS FINE

Why would it not pick up the control if the Sheet is decleared?
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
If you are using the CodeName why would you want to assign it to a Worksheet object? The syntax for a Worksheet is different from the syntax for the Class:

Rich (BB code):
SHT_Report5.OLEObjects("Image1").Object.Picture = LoadPicture("D:\testing\" & MyPictureName1 & ".png")
 
Upvote 0
o ok I see, I have alway just assigned Names to the sheets so when reading the code it is easier for me to know what is on the sheet and what sheet it is.
Thanks again for the help.
 
Upvote 0

Forum statistics

Threads
1,215,453
Messages
6,124,930
Members
449,195
Latest member
Stevenciu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top