ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Determine sheets in file (https://www.excelbanter.com/excel-programming/338091-determine-sheets-file.html)

Steph[_6_]

Determine sheets in file
 
If I had a list of files (full file path), how could I loop through them and
capture all the sheet names within each file.

For example, file names in column A, sheet names in B forward.

Thank you!



Tom Ogilvy

Determine sheets in file
 
Dim rng as Range, cell as Range, sh as Worksheet
Dim j as Long
set rng = Range(cells(1,1),Cells(1,1).End(xldown))
for each cell in rng
set bk = Workbooks.Open(cell.Value)
j = 2
for each sh in bk.Worksheets
cells(cell.row,j).Value = sh.name
j = j + 1
Next
bk.close SaveChanges:=False
Next

--
Regards,
Tom Ogilvy



"Steph" wrote in message
...
If I had a list of files (full file path), how could I loop through them

and
capture all the sheet names within each file.

For example, file names in column A, sheet names in B forward.

Thank you!





Steph[_6_]

Determine sheets in file
 
Fantastic! Thank you!

"Tom Ogilvy" wrote in message
...
Dim rng as Range, cell as Range, sh as Worksheet
Dim j as Long
set rng = Range(cells(1,1),Cells(1,1).End(xldown))
for each cell in rng
set bk = Workbooks.Open(cell.Value)
j = 2
for each sh in bk.Worksheets
cells(cell.row,j).Value = sh.name
j = j + 1
Next
bk.close SaveChanges:=False
Next

--
Regards,
Tom Ogilvy



"Steph" wrote in message
...
If I had a list of files (full file path), how could I loop through them

and
capture all the sheet names within each file.

For example, file names in column A, sheet names in B forward.

Thank you!








All times are GMT +1. The time now is 09:24 PM.

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