Opening numerious excel files

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I open 2 or more excel files in one shot? If I create a macro to
launch a diolague box, Is there a way to select numerious .xls files or does
it only have to be performed one at a time?
 
BZeyger,

Using the macro recorder you can capture this

Workbooks.Open Filename:= _
"<File 1>.xls"
Workbooks.Open Filename:="<File 2>.xls", UpdateLinks _
:=0
Workbooks.Open Filename:="<File 3>.xls", UpdateLinks _
:=0
Workbooks.Open Filename:="<File n>.xls", UpdateLinks _
:=0
 
Hello,

I found this code on microsoft.com, should work. Simple and elegant.


Sub Open_Files

'Defines the variable as a variant data type
Dim X as variant

'Continues to run the macro even if an error occurs
On Error Resume Next

'Opens the dialog
X = Application.GetOpenFilename _
("Excel Files (*.xls), *.xls, 2, "Open My Files", ,True)

'Tests the variable X to see if it is valid
If X = False then GoTo Cancel

'Loops through every file that is selected and opens each one
For Y = 1 to Ubound(X)
Workbooks.Open X(Y)
Next

Exit Sub

'If X was equal to false, displays a message and exits the
macro
Cancel:
Msgbox "The Cancel button was selected."

End Sub


Hope this helps,
JP
 

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

Back
Top