Open multiple pictures with 1 userform?

lpking2005

Board Regular
Joined
Mar 21, 2011
Messages
140
I currently have a spreadsheet with about 15 command buttons,
i want each button to open a picture.

Is there a way to have a single userform with just a image box on it, pull the different pictures, depending on which button was pressed?
Instead of creating a userform for each picture.

I was going to use simple IF and ELSE statements on the userform initialize routine, but im still learning and didnt know how to tell it to recognise which button i pressed on the sheet. :(

Any help would be much appreciated.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
When you're creating the userform, add your button and then double-click on it in design mode. This will give you the code for each button.
You can then call a different routine and pass a parameter to it so it knows what picture to use.
So the code inside each button would be:-
Call Picture_viewer(button_number) where button_number is the number of the button you've pressed.

Picture_viewer would be a separate piece of code which will sort out which picture is to be used.
Something along the lines of:-
Code:
Sub picture_viewer(picture_number)
     select case picture_number
          case 1:userform1.picture=   'code for whatever picture you want goes here'
          case 2:userform1.picture=   'code for whatever picture you want goes here'          
          case 3:userform1.picture=   'code for whatever picture you want goes here'
          case 4:userform1.picture=   'code for whatever picture you want goes here'
          case 5:userform1.picture=   'code for whatever picture you want goes here'
     end select
     userform1.repaint
end sub
 
Upvote 0
When you add the button to your userform, if you double-click on it, it will have a piece of code which will look like this:-
Code:
Private Sub CommandButton1_Click()

End Sub

In the gap (shown above), you need to add a couple of lines of code which will read:-
button_number=1
Call Picture_viewer(button_number)

That's the first step. Try that and let me know how you get on.
 
Upvote 0
OK, not a problem.
Is it a button from the forms toolbar or a button from the control toolbox toolbar?
 
Upvote 0
OK, not a problem.
When you put the button onto the spreadsheet, if you double-click on it, it will open the VBA editor and give you some code similar to this:-
Code:
Private Sub CommandButton1_Click()

End Sub

in the gap, you need to put the following:-
userform1.picture='location of picture'
userform1.show

Userform1 may need changing if you've named your userform anything other than the standard.
The location of the picture needs to have the full path and filename on it.
 
Upvote 0
I keep getting a type mismatch error, the location is definately typed right.
not sure?


Code:
Private Sub CommandButton5_Click()

PictureViewer.Picture = "T:\Production\PROD MOULDING\Digital Line Manuals\General\Pictures\Contacts\WAREHOUSE.jpg"
PictureViewer.Show

End Sub
 
Upvote 0
Dont worry i have done it now.

i had to add LoadPicture before the file location.

Code:
PictureViewer.Picture = LoadPicture("T:\Production\PROD MOULDING\Digital Line Manuals\General\Pictures\Contacts\WAREHOUSE.jpg")
PictureViewer.Show

Thanks for all your help!! :)
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,543
Members
452,924
Latest member
JackiG

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