Choose (open) workbook for actions on user prompt

E

erikhs

Hello,

The headline might not be very descriptive. My question is:
How can i get excel to recognize or let user choose, which open
workbook to process with macro, if this workbook has differing name
from time to time.
The macro now uses the "open" function, to open a workbook of choice
and then perform actions, however i i want a different action
performed(all is in user forms), i must close the workbook again. How
can i give the user the option to choose an open workbook/window while
in a sort of user form? I do not wish for something where the user has
to select a cell in the workbook and then run macro, but rather run
userform then select.

Thank You!
 
A

Ardus Petus

Create an Userform (UserForm1)
Add a ListBox (ListBox1)
Add a Command Button (CommandButton1) with caption "OK"

Paste the following code in Userform code:

'------------
Private Sub CommandButton1_Click()
MsgBox ListBox1.Value
End Sub

Private Sub UserForm_Initialize()
Dim wb As Workbook
With ListBox1
For Each wb In Workbooks
If wb.Name <> ThisWorkbook.Name Then
.AddItem (wb.Name)
End If
Next wb
.ListIndex = 1
End With
End Sub
'---------------------

Et voilà!

HTH
 

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