Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Code to Open multiple files from directory

  Asked By: Ella    Date: Sep 21    Category: MS Office    Views: 936
  

What is the code to open all the files in a folder?
For example:
C:\My Documents\VBA
file1.xls
file2.xls
file3.xls
file4.xls
file5.xls

Is it possible to open just the first 3 files?

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Abbas Hashmi     Answered On: Sep 21

Try this code:

Sub OpenMultipleFiles()
FilesToOpen = Application.GetOpenFilename(FileFilter:="Excel Workbooks
(*.xls),*.xls", Title:="Opening multiple  Files..", MultiSelect:=True)
For n = 1 To UBound(FilesToOpen )
Workbooks.Open FilesToOpen (n)
Next n
End Sub

When you run this macro, it will pop up a File Open window. You can navigate
to the directory  you want and select multiple files  by pressing CTRL key and
clicking on each file.

 
Didn't find what you were looking for? Find more on Code to Open multiple files from directory Or get search suggestion and latest updates.




Tagged: