Controls not located when Worksheet is defined (VBA)

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
I have an activeX image control on a Worksheet.

It works fine when do things like :

Code:
Sheet1.Image1.Picture = LoadPicture("")

OR
Code:
With Sheet1 
     .Image1.Picture = LoadPicture("")
End With

But when I do:

Code:
Dim Sh As Worksheet 
Set Sh = Sheet1
Sh.Image1.Picture = LoadPicture("")

It says the control can't be found.

Can someone tell me why the last code is not working?

Thanks in advance.
Kelly
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try:
VBA Code:
Sh.shapes("Image1").Picture = LoadPicture("")
And i would recommend also to use fully qualified references, e.g.
VBA Code:
Set Sh = Thisworbook.Worksheets("Sheet1")
 
Upvote 0
The Worksheet class doesn’t have an Image1 property. Declare the variable as Object or as Sheet1
 
Upvote 0
Try:
VBA Code:
Sh.shapes("Image1").Picture = LoadPicture("")
And i would recommend also to use fully qualified references, e.g.
VBA Code:
Set Sh = Thisworbook.Worksheets("Sheet1")
Now the error didn't show up but the code that loads image into the control didn't load the image.
 
Upvote 0
The Worksheet class doesn’t have an Image1 property. Declare the variable as Object or as Sheet1
I am not getting what you mean clearly - can you give an example please?
 
Upvote 0
Use either:

Code:
Dim Sh As Object

or:

Code:
Dim Sh As Sheet1
 
Upvote 0
Solution
If you want to use a Worksheet variable, you can refer to the control using the OLEObjects collection:

Code:
sh.oleobjects("image1").object
 
Upvote 0

Forum statistics

Threads
1,214,885
Messages
6,122,085
Members
449,064
Latest member
MattDRT

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