Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 137
Default toggle open files

I have this code to list the sheets in an active workbook:

Sub listSheets()

Dim x As Worksheet

For Each x In Application.Worksheets
ActiveCell.Value = x.Name
ActiveCell.Offset(1, 0).Activate
Next x

End Sub

.... but would like to list sheets in another open book without activating it.

Thanks in anticpation.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default toggle open files

Use this, or optionally replace the Worksheets collection with the Sheets
collection instead, which also contains Charts (if any are available)

/MP

===============================


Option Explicit

Public Sub ListAllBooksAndSheets()
Dim wb As Workbook
Dim ws As Worksheet

For Each wb In Application.Workbooks
Debug.Print "= Workbook: " & wb.Name
For Each ws In wb.Worksheets
Debug.Print "== Worksheet: " & ws.Name
Next ws
Next wb

End Sub

===============================

"Newbie" wrote:

I have this code to list the sheets in an active workbook:

Sub listSheets()

Dim x As Worksheet

For Each x In Application.Worksheets
ActiveCell.Value = x.Name
ActiveCell.Offset(1, 0).Activate
Next x

End Sub

... but would like to list sheets in another open book without activating it.

Thanks in anticpation.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default toggle open files

Sub listSheets()
Dim x as Worksheet
Dim file1 As Workbook
Set file1 = Workbooks("Other_Workbook.xls")
For Each x In file1.Worksheets
ActiveCell.Value = x.Name
ActiveCell.Offset(1, 0).Activate
Next x


That should work as long as the other workbook is already open.

Die_Another_Day

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
alt-tab toggle betw files/programs wilson@irco Excel Discussion (Misc queries) 0 January 7th 09 07:37 PM
how do I toggle between 2 open excel files and leave both open Big D in Brighton Excel Discussion (Misc queries) 1 November 6th 08 04:28 PM
How to change default Open/Files of Type to "Microsoft Excel Files Tammy Excel Discussion (Misc queries) 2 January 14th 08 11:06 PM
Can I toggle between files easily bweller Excel Discussion (Misc queries) 2 May 25th 06 05:11 PM
toggle button or worksheet_activate causing form to open twice Tom Ogilvy Excel Programming 5 April 16th 05 02:58 AM


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

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

About Us

"It's about Microsoft Excel"