ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Displaying a picture by pushing CommandButton (https://www.excelbanter.com/excel-programming/323003-displaying-picture-pushing-commandbutton.html)

Jean[_4_]

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


Tom Ogilvy

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




K Dales[_2_]

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



K Dales[_2_]

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



Jean[_4_]

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



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com