Consulting

Results 1 to 6 of 6

Thread: Image Preview

  1. #1

    Image Preview

    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.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Mike,
    Welcome to VBAX
    Can you post a simple sample? Use Manage Attachments in the Go Advanced section.
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    Mike,
    You should be able to use something along these lines:
    [VBA]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
    [/VBA]

    Regards,
    Rory

  4. #4
    Attached is a small, stripped down version of what I am working with. The preview images are in a directory called c:\images.

  5. #5
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    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...
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  6. #6
    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •