how to open all hidden .xls files

C

calebjill

I have some code to open all excel files in a folder, but it will only open
the files that are not hidden. Is there a way to open all the files
regardless of hidden status.

Here is the code.

Sub open_all_files()
Dim path As Variant
Dim excelfile As Variant
path = "c:/users/caleb/documents/commissions experiment/"

excelfile = Dir(path & "*.xls")
Do While excelfile <> ""
Workbooks.Open Filename:=path & excelfile
excelfile = Dir
Loop
End Sub

Thanks
 
D

Dave Peterson

There's a second parm you can pass to the dir() function.

excelfile = Dir(path & "*.xls"), vbHidden)

VBA's help has more information.
 
C

calebjill

Thanks Dave

Dave Peterson said:
There's a second parm you can pass to the dir() function.

excelfile = Dir(path & "*.xls"), vbHidden)

VBA's help has more information.
 

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