Button in userform

J

Jarle

I store a list of documents in an array called Hitfiles.
The size of this array may vary.

I create buttons in an userform using VBA like this. (I leave out info like
position of button)

For i = LBound(Hitfiles) To UBound(Hitfiles)
With .Controls.Add("Forms.CommandButton.1", "Button" & i, True)
.Caption = Filename
.Name = "button" & i
End With

If array has 5 elements, then 5 buttons called Button1, Button2....Button5
will be created in the userform. (Array is size 1 to 5)

I want document 1 to open when I press button 1, document 2 to open when I

How can I run a macro from the buttons I have just created?

Thanks!

rgds
Jarle
 

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