PDA

View Full Version : Image Preview



mike0123m
08-06-2007, 01:51 PM
I wrote an excel program that contains 12 tabs. When the program is first launched, a userform pops up that contains a row of commandbuttons and on each button is a small icon that relates to each tab of the spreadsheet. Since the icons are so small and there is very little detail to them, I'd like to add an image box on the userform so that when a button with the icon is clicked on, a larger and more detailed version of the icon appears in the preview box. If the picture shown in the preview box is what the user wants to do, then clicking the ok button on the userform will take the user to the tab that contains the data for that particular icon. That's a lot of programming that I'm unfamiliar with. At first I was just going to link the icons with a macro that will switch to the appropriate tab but I would really like to make the preview box work.

mdmackillop
08-07-2007, 12:30 AM
Hi Mike,
Welcome to VBAX
Can you post a simple sample? Use Manage Attachments in the Go Advanced section.
Regards
MD

rory
08-07-2007, 02:05 AM
Mike,
You should be able to use something along these lines:
Private Sub CommandButton1_Click()
SetPic CommandButton1
End Sub
Private Sub CommandButton2_Click()
SetPic CommandButton2
End Sub
Private Sub CommandButton3_Click()
SetPic CommandButton3
End Sub
Private Sub CommandButton4_Click()
SetPic CommandButton4
End Sub
Sub SetPic(ctl As CommandButton)
Dim strPath As String
strPath = "C:\img.jpg"
If Dir(strPath) <> "" Then Kill strPath
SavePicture ctl.Picture, strPath
With Me.Image1
.Picture = LoadPicture(strPath)
.PictureSizeMode = fmPictureSizeModeStretch
End With
End Sub


Regards,
Rory

mike0123m
08-07-2007, 03:50 AM
Attached is a small, stripped down version of what I am working with. The preview images are in a directory called c:\images.

lucas
08-09-2007, 01:49 PM
Hi Mike,
First problem I see is that you have an image on top of your button so that when you click on it you are actually clicking on the image rather than the button. Remove the images and use the buttons properties...view-properties window in the vbe. Then look for a property called Picture. Click in the blank box to the right of the word and browse for your picture...

mike0123m
08-09-2007, 03:31 PM
Ok, I fixed that mistake. But then how do I get the program to switch to the correct tab in the spreadsheet based on the image that appears in the image box?