Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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" wrote in message
oups.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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default 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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default 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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying a Picture with a Macro JB Bates[_2_] Excel Discussion (Misc queries) 1 November 2nd 09 10:48 PM
Retreiving and displaying picture based on criteria from validatio Rob R. Excel Discussion (Misc queries) 0 June 3rd 09 10:28 PM
displaying an excel-linked jpg in picture and fax viewer ZR1991 Excel Discussion (Misc queries) 0 September 21st 07 10:46 PM
Displaying a picture Todd Excel Programming 1 July 16th 04 02:18 PM
displaying picture in a userform Todd Huttenstine[_3_] Excel Programming 1 January 28th 04 02:42 AM


All times are GMT +1. The time now is 11:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"