VB Code question...

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
I currently have a script set to open 2 specific workbooks and then prompt to choose the required 3rd.

As it is, I can only select 1 when the 'open' window comes up. Is there any way I can make this so I am able to select more than one file at once?

The code I currently have is as follows:
Private Sub Workbook_Open()
On Error GoTo myErr
ChDir "(directory)"
Workbooks.Open "(file.xls)"
Workbooks.Open "(file.xls)"
Which = Application.GetOpenFilename() 'prompts user to open 3rd

Workbooks.Open Which
End
myErr:
End Sub
_________________
"What am I, a magnet for these idiots?"
--Pearl Forrester, MST3K
This message was edited by Von Pookie on 2002-02-20 14:01
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
You just need to set the Multiselect argument to True e.g.

Which = Application.GetOpenFilename(MultiSelect:=True)
'Which now contains an array of file names which you can enumerate through
For l = 1 To UBound(Which)
MsgBox Which(l)
Next

HTH,
D
 
Upvote 0
This does let me select more than one file, however, it will not open them. The only thing that happens when I click 'open' is that I get a message box that tells me the files I selected.

I tried deleting the "MsgBox Which(l)" line, however then it doesn't do anything...
 
Upvote 0
On 2002-02-21 07:40, Von Pookie wrote:
This does let me select more than one file, however, it will not open them. The only thing that happens when I click 'open' is that I get a message box that tells me the files I selected.

I tried deleting the "MsgBox Which(l)" line, however then it doesn't do anything...

You may want to put:

Workbooks.Open Which (l)

where that "Msgbox Which(l)" was before.
 
Upvote 0
On 2002-02-21 09:15, Mark O'Brien wrote:
You may want to put:

Workbooks.Open Which (l)

where that "Msgbox Which(l)" was before.

Unfortunately, I can't get that to work either.

This is what I'm working with now:
Code:
Private Sub Workbook_Open()
On Error GoTo myErr
ChDir "(dir)"
Workbooks.Open "(file).xls"
Workbooks.Open "(file).xls"
Which = Application.GetOpenFilename(MultiSelect:=True)
'Which now contains an array of file names which you can enumerate through
For l = 1 To UBound(Which)
Workbooks.Open Which (l)
Next
Workbooks.Open Which
End
myErr:
End Sub

_________________
"What am I, a magnet for these idiots?"
--Pearl Forrester, MST3K
This message was edited by Von Pookie on 2002-02-21 09:26
 
Upvote 0
Try this:

Code:
Private Sub Workbook_Open()
On Error GoTo myErr
ChDir "C:Documents and SettingsksharpeDesktopECR"
Workbooks.Open "C:Documents and SettingsksharpeDesktopECRUPGUPG List Revised.xls"
Workbooks.Open "C:Documents and SettingsksharpeDesktopECRMain Directory.xls"
Which = Application.GetOpenFilename(MultiSelect:=True)
'Which now contains an array of file names which you can enumerate through
For I = 1 To UBound(Which)
   Workbooks.Open Which(I)
Next

End
myErr:
End Sub
This message was edited by Russell Hauf on 2002-02-21 09:27
 
Upvote 0

Forum statistics

Threads
1,214,405
Messages
6,119,323
Members
448,887
Latest member
AirOliver

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