View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
modo8 modo8 is offline
external usenet poster
 
Posts: 6
Default Put worksheet names from inactive file into cells of active worksh


Hello-

I'm building a macro to go through a list of file names; for any .xls files
in that list, I want to create a list of the worksheets in that file. I want
to create this new list in the "master" file that stores the macro.

I would prefer if I could keep the focus on the "master" sheet, and pull in
the names from the open, but inactive, .xls file. The code below is my
attempt to do that, but I get a "Subscript out of range (Error 9)".

I'm open to other solutions that have the end result of putting a list of
tab names on the master sheet without altering any content in the other .xls
files. I also tried keeping the focus on the .xls file and sending the
results to the inactive master sheet, but that didn't fare any better.

Thank you all, these boards are incredibly helpful to those people like me
who get in over their heads with random Excel projects :)

My code:

Do Until HRow = GRow
Windows("Info Delivery Version 2.xls").Activate ***The "Master Sheet"
Sheets("Sheet1").Activate

FileName = Range("C" & HRow)
FileType = Range("D" & HRow)

If FileType < ".zip" Then
Application.EnableEvents = False
Workbooks.Open FileName:=Path & FileName
End If

Windows("Info Delivery Version 2.xls").Activate
Sheets("Sheet1").Activate

If FileType = ".xls" Then
Dim WS As Worksheet
For Each WS In Windows("FileName").Sheets ***Here's where I get an
error
Range("G" & IRow) = FileName
Range("H" & IRow) = WS.Name
IRow = IRow + 1
Next
ElseIf FileType < ".zip" Then
Range("G" & IRow) = Range("C" & HRow)
IRow = IRow + 1
End If
HRow = HRow + 1
Loop