Running macro automatic after opening Userform

X

Xentis

Dear all,

I have the following problem: I'd created a userform with a Image
field. Now I'd like to asign a picture to that image field at the
moment you open the userform. I just can't get the macro to run
automatic after opening of the userform.

The code:

-----------------------------------------------------------------------
---------------------

Public Sub ShowPicture()

Dim CurrentChart1, Fname1

Set CurrentChart1 = Sheets("Picture").ChartObjects(1).Chart
Fname1 = ThisWorkbook.Path & "\temp1.gif"
CurrentChart1.Export Filename:=Fname1, FilterName:="GIF"

UserForm1.Show

Application.run "CommandButton1_Click"

End Sub

-----------------------------------------------------------------------
----------------------

Private Sub CommandButton1_Click()

Path1 = "c:"
Fname1 = Path1 & "\temp1.gif"
Image1.Picture = LoadPicture(Fname1)

End Sub
-----------------------------------------------------------------------
------------------------.

When I build Commandbutton1 on the Userform and click it, the picture
will show in the image field. I just like it to do it automatically
when i open the Userform. Anyone a solution?
 
X

Xentis

Mike,

Thanks for your answer. It is better to use the call option.

In this case however I get a "Object variable or with block variable
not set"

I can't seem to get the first macro to recognize the image field in
the form. I 've now tried the code below
But it also gives a "Object required" error.

-----------------------------------------------------------------------
---------------
Public Sub ShowPicture()

Dim CurrentChart1, Fname1

Set CurrentChart1 = Sheets("Picture").ChartObjects(1).Chart
Fname1 = ThisWorkbook.Path & "\temp1.gif"
CurrentChart1.Export Filename:=Fname1, FilterName:="GIF"

UserForm1.Show vb Modeless

Path1 = "c:"
Fname1 = Path1 & "\temp1.gif"
Image1.Picture = LoadPicture(Fname1)

End Sub

-----------------------------------------------------------------------
--------------------

I'm not very experienced with this kind of problems so if anybody
could help I would be really glad.

Regards,

Xentis
 
R

Ron de Bruin

Hi Xentis
moment you open the userform. I just can't get the macro to run
automatic after opening of the userform.

Call your macro in this event in the Userform module

Private Sub UserForm_Initialize()
Call yourmacroname
End Sub
 
X

Xentis

He Rob,

Dat doet het inderdaad. Super, Excel is best leuk als het werkt :p.

gr,

Xentis
 

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