+ Reply to Thread
Results 1 to 6 of 6

Displaying a picture by pushing CommandButton

  1. #1
    Jean
    Guest

    Displaying a picture by pushing CommandButton

    Hi,

    I am relatively new at Excel VBA, but have used Access VBA in the past
    and need a few tips to do the following seemingly simple task.

    I have a spreadsheet, with a comand button cmdShowPic. When the user
    clicks on cmdShowPic, it must show a picture that I specify.

    My question is: how do I implement this? To start, do I simply copy and
    paste the pic into the spreadsheet? And how do I caal a method that
    will show the pic? I am not sure how to do this, maybe with a User
    Form?

    Thanks in advance for the help!

    J


  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Jean,

    You can place an Image Control on the Worksheet. Afterwards right click the Image Control and select Properties. Change the AutoSize Property to True. Close the Properties Window. Right Click the CommandButton and select View Code.

    Place the Following Code in the Command Button's Click Event

    Image1.Picture = stdole.LoadPicture("C:\My Documents\Picture 1.jpg")

    This will display all the common picture files as well as icons and cursors.

    Hope this helps,
    Leith Ross

  3. #3
    Tom Ogilvy
    Guest

    Re: Displaying a picture by pushing CommandButton

    If you already have it on the sheet in the position you want:

    Private Sub cmdShowPic_Click()
    With ActiveSheet.Pictures(1)
    .Visible = Not .Visible
    End With
    End Sub

    this was for a picture entered in the sheet using Insert=>Picture (from
    file).

    If you need to do that, turn on the macro recorder while you do it manually
    (tools=>Macros => Record a new macro, insert the picture, then click the
    stop recording button, or if it is not visible Tools=>Macros=>Stop
    Recording. Then you can examine the code recorded and generalize it if
    necessary).

    --
    Regards,
    Tom Ogilvy


    "Jean" <jeanjanssens@hotmail.com> wrote in message
    news:1108298438.346666.146100@g14g2000cwa.googlegroups.com...
    > Hi,
    >
    > I am relatively new at Excel VBA, but have used Access VBA in the past
    > and need a few tips to do the following seemingly simple task.
    >
    > I have a spreadsheet, with a comand button cmdShowPic. When the user
    > clicks on cmdShowPic, it must show a picture that I specify.
    >
    > My question is: how do I implement this? To start, do I simply copy and
    > paste the pic into the spreadsheet? And how do I caal a method that
    > will show the pic? I am not sure how to do this, maybe with a User
    > Form?
    >
    > Thanks in advance for the help!
    >
    > J
    >




  4. #4
    K Dales
    Guest

    RE: Displaying a picture by pushing CommandButton

    I like the idea of a popup userform with the picture on it, and it is not too
    hard to do: First, create the userform and size it however you like. You
    don't need to add any controls on it, because you can use the form's own
    background to display the picture. Then, create the button and assign this
    code to it:
    With UserForm1
    .Picture = LoadPicture(Sheets("Sheet1").Range("A1").Value)
    .Show
    .Picture = LoadPicture ' with no arguments, this clears the current picture
    End With

    You can set the userform to a fixed size (in which case I suggest you set
    the picturesizemode to Zoom) or, if necessary, you could find out how big the
    picture is and scale the form accordingly, but that gets messy so I won't
    attempt that here! But hope it gives you a start, at least.

    "Jean" wrote:

    > Hi,
    >
    > I am relatively new at Excel VBA, but have used Access VBA in the past
    > and need a few tips to do the following seemingly simple task.
    >
    > I have a spreadsheet, with a comand button cmdShowPic. When the user
    > clicks on cmdShowPic, it must show a picture that I specify.
    >
    > My question is: how do I implement this? To start, do I simply copy and
    > paste the pic into the spreadsheet? And how do I caal a method that
    > will show the pic? I am not sure how to do this, maybe with a User
    > Form?
    >
    > Thanks in advance for the help!
    >
    > J
    >
    >


  5. #5
    K Dales
    Guest

    RE: Displaying a picture by pushing CommandButton

    Should have specified, but should be obvious: I had my picture path stored in
    the cell A1 of sheet "Sheet1" - but you can use any text string here so just
    supply your file path to the picture file as the parameter for the
    LoadPicture function.

    "K Dales" wrote:

    > I like the idea of a popup userform with the picture on it, and it is not too
    > hard to do: First, create the userform and size it however you like. You
    > don't need to add any controls on it, because you can use the form's own
    > background to display the picture. Then, create the button and assign this
    > code to it:
    > With UserForm1
    > .Picture = LoadPicture(Sheets("Sheet1").Range("A1").Value)
    > .Show
    > .Picture = LoadPicture ' with no arguments, this clears the current picture
    > End With
    >
    > You can set the userform to a fixed size (in which case I suggest you set
    > the picturesizemode to Zoom) or, if necessary, you could find out how big the
    > picture is and scale the form accordingly, but that gets messy so I won't
    > attempt that here! But hope it gives you a start, at least.
    >
    > "Jean" wrote:
    >
    > > Hi,
    > >
    > > I am relatively new at Excel VBA, but have used Access VBA in the past
    > > and need a few tips to do the following seemingly simple task.
    > >
    > > I have a spreadsheet, with a comand button cmdShowPic. When the user
    > > clicks on cmdShowPic, it must show a picture that I specify.
    > >
    > > My question is: how do I implement this? To start, do I simply copy and
    > > paste the pic into the spreadsheet? And how do I caal a method that
    > > will show the pic? I am not sure how to do this, maybe with a User
    > > Form?
    > >
    > > Thanks in advance for the help!
    > >
    > > J
    > >
    > >


  6. #6
    Jean
    Guest

    Re: Displaying a picture by pushing CommandButton

    Thanks to both of you!

    I showed both methods to a client, and he will decide on his own which
    one to use. Both solutions were easy enough for them to take care of.

    Regards,
    Jean


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1