Using pictures in Userforms

G

Guest

Hi there,
until recently used Message Boxes to give the user information. However as
of right now I need to give more information and the upkeep in the current
format requires me to change the code so that the apearance is uniform.

I have tables in a seperate worksheet which I managed to turn into pictures.
I intend to load them on userforms which will pop-up after double-clicks.(The
tables will change dynamicly so copy and paste in the properties window of a
image won't work I guess)

My question is how do I load them from the worksheet into a Userform? Do I
need to export them first and then import them back? Or do I even need
Userforms in the first place can I display pictures in Msg Boxes?

Thank you,
Ozgur
 
G

Guest

Put this macro into a module:

Sub example()
ActiveChart.Export "temp.jpg", "JPG", True
UserForm1.Show
On Error Resume Next
Unload UserForm1
Kill "temp.jpg"
On Error GoTo 0
End Sub


Then, in your Userform (e.g. UserForm1), create an image control (e.g.
called "Image1"), and a command button called "CommandButton1"). Set the
Autosize property of the image control to true.

Place the code below into the form.

Private Sub UserForm_Activate()
Image1.Picture = LoadPicture("temp.jpg")
End Sub

Private Sub CommandButton1_Click()
Me.Hide
End Sub


With a chart selected, run the macro "example".

I also put a sample file in my web site:
http://www.vonixx.com/excel/chart_in_form.xls

Regards,
Edwin Tam
(e-mail address removed)
http://www.vonixx.com
 
G

Guest

Edwin thank you for your response.
I did copy your code into a module and userform and it works great with a
chart. However I was wondering if I can do the same export with a picture(I
have a range of cells saved as a picture)?
This does not work...
ActiveSheet.Shapes("Picture 1").Export "temp.jpg", "JPG", True

Any thoughts?

Thanks again for your help.

Özgür
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top