ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   how to open all hidden .xls files (https://www.excelbanter.com/excel-discussion-misc-queries/218190-how-open-all-hidden-xls-files.html)

calebjill

how to open all hidden .xls files
 
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

Dave Peterson

how to open all hidden .xls files
 
There's a second parm you can pass to the dir() function.

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

VBA's help has more information.

calebjill wrote:

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


--

Dave Peterson

calebjill

how to open all hidden .xls files
 
Thanks Dave

"Dave Peterson" wrote:

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

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

VBA's help has more information.

calebjill wrote:

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


--

Dave Peterson



All times are GMT +1. The time now is 02:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com