Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Hal Hal is offline
external usenet poster
 
Posts: 36
Default Open Workbooks, Used Area on Sheet

I would like to add the capability to the sub below of getting the name of
each worksheet within the open workbooks. I tried nesting a For Each
wsNames(j) within the For Each wb in Application.Workbooks loop. I was not
able to resolve the errors.

Your suggestions are appreciated.


Sub wbsOpen()
' Get the names of all open workbooks and store in an array
Dim wbNames(), wsNames() As String
Dim i, j As Integer, wb As Workbook, ws as Worksheet

ReDim wbNames(1 To Workbooks.Count)

i = 1
For Each wb In Application.Workbooks
wbNames(i) = wb.FullName
Debug.Print wbNames(i)
i = i + 1
Next
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Open Workbooks, Used Area on Sheet


Sub wbsOpen()
Dim wb As Workbook, ws As Worksheet
For Each wb In Application.Workbooks
Debug.Print wb.FullName
For Each ws In wb.Sheets
Debug.Print ws.Name
Next
Next
End Sub


Regards,
Shailesh Shah
http://in.geocities.com/shahshaileshs/
If You Can't Excel with Talent, Triumph with Effort.

http://in.geocities.com/shahshaileshs/menuaddins
(Free addins old\classic Office Menu-2003 for Office-2007)


"Hal" wrote in message
...
I would like to add the capability to the sub below of getting the name of
each worksheet within the open workbooks. I tried nesting a For Each
wsNames(j) within the For Each wb in Application.Workbooks loop. I was not
able to resolve the errors.

Your suggestions are appreciated.


Sub wbsOpen()
' Get the names of all open workbooks and store in an array
Dim wbNames(), wsNames() As String
Dim i, j As Integer, wb As Workbook, ws as Worksheet

ReDim wbNames(1 To Workbooks.Count)

i = 1
For Each wb In Application.Workbooks
wbNames(i) = wb.FullName
Debug.Print wbNames(i)
i = i + 1
Next
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
Hal Hal is offline
external usenet poster
 
Posts: 36
Default Open Workbooks, Used Area on Sheet

Thanks for the help Shah,

Taking your example I cam up with the following. However, I am not able to
ReDim the wsNames() array without creating the error subscript out of range
after the first workbook is parsed. If the define the wsNames(1 to 10) I get
the results. But I would really like to set the array to cover all open
workbooks.

This type of programming is not for a rookie 'programmer' like me.

Anyone with the know how to set this up correctly? Thanks in advance.

Sub wbsOpen()
' Get the names of all open workbooks and store in an array
Dim wbNames(), wsNames() As String
Dim i, j As Integer, wb As Workbook, ws As Worksheet
Dim cSheets As Integer

ReDim wbNames(1 To Workbooks.Count)

i = 1: j = 1
For Each wb In Application.Workbooks
wbNames(i) = wb.FullName
Debug.Print wbNames(i)
ReDim Preserve wsNames(1 To wb.Sheets.Count)
For Each ws In wb.Sheets
wsNames(j) = ws.Name
Debug.Print wsNames(j)
j = j + 1
Next
i = i + 1
Next
End Sub


"Shah Shailesh" wrote:


Sub wbsOpen()
Dim wb As Workbook, ws As Worksheet
For Each wb In Application.Workbooks
Debug.Print wb.FullName
For Each ws In wb.Sheets
Debug.Print ws.Name
Next
Next
End Sub


Regards,
Shailesh Shah
http://in.geocities.com/shahshaileshs/
If You Can't Excel with Talent, Triumph with Effort.

http://in.geocities.com/shahshaileshs/menuaddins
(Free addins old\classic Office Menu-2003 for Office-2007)


"Hal" wrote in message
...
I would like to add the capability to the sub below of getting the name of
each worksheet within the open workbooks. I tried nesting a For Each
wsNames(j) within the For Each wb in Application.Workbooks loop. I was not
able to resolve the errors.

Your suggestions are appreciated.


Sub wbsOpen()
' Get the names of all open workbooks and store in an array
Dim wbNames(), wsNames() As String
Dim i, j As Integer, wb As Workbook, ws as Worksheet

ReDim wbNames(1 To Workbooks.Count)

i = 1
For Each wb In Application.Workbooks
wbNames(i) = wb.FullName
Debug.Print wbNames(i)
i = i + 1
Next
End Sub




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Open Workbooks, Used Area on Sheet


Sub wbsOpen()

' Get the names of all open workbooks and store in an array
Dim wbNames() As String, wsNames() As String
Dim i As Long, j As Long
Dim wb As Workbook, ws As Worksheet

For Each wb In Application.Workbooks

i = i + 1
ReDim Preserve wbNames(1 To i)
wbNames(i) = wb.FullName
Debug.Print wbNames(i)

For Each ws In wb.Worksheets

j = j + 1
ReDim Preserve wsNames(1 To j)
wsNames(j) = ws.Name
Debug.Print wsNames(j)

Next

Next


'for testing array on the sheet

Sheets.Add ' create new worksheet

'put array to range

Range("a1").Resize(i).Value = Application.Transpose(wbNames)
Range("b1").Resize(j).Value = Application.Transpose(wsNames)
Cells.Columns.AutoFit

End Sub



Regards,
Shailesh Shah
http://in.geocities.com/shahshaileshs/
If You Can't Excel with Talent, Triumph with Effort.

http://in.geocities.com/shahshaileshs/menuaddins
(Free addins old\classic Office Menu-2003 for Office-2007)



"Hal" wrote in message
...
Thanks for the help Shah,

Taking your example I cam up with the following. However, I am not able to
ReDim the wsNames() array without creating the error subscript out of
range
after the first workbook is parsed. If the define the wsNames(1 to 10) I
get
the results. But I would really like to set the array to cover all open
workbooks.

This type of programming is not for a rookie 'programmer' like me.

Anyone with the know how to set this up correctly? Thanks in advance.

Sub wbsOpen()
' Get the names of all open workbooks and store in an array
Dim wbNames(), wsNames() As String
Dim i, j As Integer, wb As Workbook, ws As Worksheet
Dim cSheets As Integer

ReDim wbNames(1 To Workbooks.Count)

i = 1: j = 1
For Each wb In Application.Workbooks
wbNames(i) = wb.FullName
Debug.Print wbNames(i)
ReDim Preserve wsNames(1 To wb.Sheets.Count)
For Each ws In wb.Sheets
wsNames(j) = ws.Name
Debug.Print wsNames(j)
j = j + 1
Next
i = i + 1
Next
End Sub


"Shah Shailesh" wrote:


Sub wbsOpen()
Dim wb As Workbook, ws As Worksheet
For Each wb In Application.Workbooks
Debug.Print wb.FullName
For Each ws In wb.Sheets
Debug.Print ws.Name
Next
Next
End Sub


Regards,
Shailesh Shah
http://in.geocities.com/shahshaileshs/
If You Can't Excel with Talent, Triumph with Effort.

http://in.geocities.com/shahshaileshs/menuaddins
(Free addins old\classic Office Menu-2003 for Office-2007)


"Hal" wrote in message
...
I would like to add the capability to the sub below of getting the name
of
each worksheet within the open workbooks. I tried nesting a For Each
wsNames(j) within the For Each wb in Application.Workbooks loop. I was
not
able to resolve the errors.

Your suggestions are appreciated.


Sub wbsOpen()
' Get the names of all open workbooks and store in an array
Dim wbNames(), wsNames() As String
Dim i, j As Integer, wb As Workbook, ws as Worksheet

ReDim wbNames(1 To Workbooks.Count)

i = 1
For Each wb In Application.Workbooks
wbNames(i) = wb.FullName
Debug.Print wbNames(i)
i = i + 1
Next
End Sub






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why I get gray area in sheet tab of page setup? can't resize area. joey0617 Excel Discussion (Misc queries) 1 July 15th 06 05:30 PM
When I open Excel, workbooks open automatically. How can I stop t Rhealbird Excel Discussion (Misc queries) 2 February 23rd 06 10:08 AM
workbooks.open function fails to open an existing excel file when used in ASP, but works in VB. san Excel Programming 1 January 3rd 06 03:22 AM
Excel 2003 Workbooks.Open with CorruptLoad=xlRepairFile fails on Excel 5.0/95 file due to Chart, with Error 1004 Method 'Open' of object 'Workbooks' failed Frank Jones Excel Programming 2 June 15th 04 03:21 AM
comparing cells in different workbooks - open a certain sheet Walt[_2_] Excel Programming 0 July 28th 03 06:46 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"