Disposable/Dynamic Listbox

HWL

Active Member
Joined
Dec 1, 2009
Messages
462
I'm trying to have a macro that creates a list box of the names of the open Excel files so the user can select, which will continue my code on the file selected.

I thought something like this would work but it isn't:
Dim wbk As Workbook
For Each wbk In Workbooks
'loop through the Open workbooks
If wbk.Name <> ThisWorkbook.Name Then
'exclude this workbook from the Loop
else
ListBox1.additem wbk.name
next wbk
Endif
This fails as saying the Next needs a For even though there is a FOR.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
The End If and Next are the wrong way round.
 
Upvote 0
Where is the listbox and where is the code?
 
Upvote 0
Where is the listbox and where is the code?

Well, I've tried both ways. I created a userform, added a list box to it then ran the code. But ideally I'd like it to create the listbox when the code is ran and delete it when done.

The error I get is:
Run Error '424' - Object Required

I'd assume this means that the ListBox1 doesn't exist therefore the "additem" code fails.
 
Upvote 0
So where is the code located?

PS Why do you want to delete the listbox? You could just hide it, or if it's on a userform close the userform.
 
Upvote 0

Forum statistics

Threads
1,225,071
Messages
6,182,685
Members
453,132
Latest member
nsnodgrass73

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top