Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Get a List of Worksheets

Hi --

I have some workbooks that have 100+ worksheets in them.
I'd like to have a list of the worksheets printed in a worksheet (or
any list of cells).

I found this code on the MSDN:

Private Sub ListSheets()
Dim sh As Excel.Worksheet
Dim rng As Excel.Range
Dim i As Integer

rng = ThisApplication.Range("rangeSheets")
For Each sh In ThisWorkbook.Sheets
rng.Offset(i, 0).Value = sh.Name
i = i + 1
Next sh
End Sub

I created a range of cells called rangeSheets.
This code does not work as is. It must need some
kind of modification that's not obvious.

I have two problems.....
1) I had the remove the word private for it to be visible in the
macros list (OK after that I think)

2) It creates a run time error at this line
rng = ThisApplication.Range("rangeSheets")
I've tried:
set rng = ThisApplication.Range("rangeSheets")
and
rng = ThisApplication.Range("A1")

nothing changes.

Any suggestion how to get a list of worksheets or how to use this
code?

Thanks
Brad


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Get a List of Worksheets

Hi Brad

That code was pretty messy and should definitely err, is it really from
MSDN? Try

Sub ListSheets()
Dim sh As Excel.Worksheet
For Each sh In ThisWorkbook.Worksheets
Sheets(1).Cells(sh.Index, 1).Value = sh.Name
Next sh
End Sub

(Note that it's worksheets, which you wanted, chart sheets will not get
listed.

HTH. Best wishes Harald

"glonka " skrev i melding
...
Hi --

I have some workbooks that have 100+ worksheets in them.
I'd like to have a list of the worksheets printed in a worksheet (or
any list of cells).

I found this code on the MSDN:

Private Sub ListSheets()
Dim sh As Excel.Worksheet
Dim rng As Excel.Range
Dim i As Integer

rng = ThisApplication.Range("rangeSheets")
For Each sh In ThisWorkbook.Sheets
rng.Offset(i, 0).Value = sh.Name
i = i + 1
Next sh
End Sub

I created a range of cells called rangeSheets.
This code does not work as is. It must need some
kind of modification that's not obvious.

I have two problems.....
1) I had the remove the word private for it to be visible in the
macros list (OK after that I think)

2) It creates a run time error at this line
rng = ThisApplication.Range("rangeSheets")
I've tried:
set rng = ThisApplication.Range("rangeSheets")
and
rng = ThisApplication.Range("A1")

nothing changes.

Any suggestion how to get a list of worksheets or how to use this
code?

Thanks
Brad


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Get a List of Worksheets

thanks so much -- that works just fine!!!


Here is the offending URL
http://tinyurl.com/6nll

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Get a List of Worksheets

Thanks. Incredible. That code can't have been tested ever. It should at
least read
Set rng = Range("rangeSheets")
-ranges must be assigned with "Set". And "ThisApplication" is, in this
context, pure nonsense.

Best wishes Harald

"glonka " skrev i melding
...
thanks so much -- that works just fine!!!


Here is the offending URL
http://tinyurl.com/6nlly


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Get a List of Worksheets

If you adjust one line, it works oK (and have a defined name rangesheets).

Private Sub ListSheets()
Dim sh As Excel.Worksheet
Dim rng As Excel.Range
Dim i As Integer

Set rng = Application.Range("rangeSheets")
For Each sh In ThisWorkbook.Sheets
rng.Offset(i, 0).Value = sh.Name
i = i + 1
Next sh
End Sub

--
Regards,
Tom Ogilvy

"Harald Staff" wrote in message
...
Hi Brad

That code was pretty messy and should definitely err, is it really from
MSDN? Try

Sub ListSheets()
Dim sh As Excel.Worksheet
For Each sh In ThisWorkbook.Worksheets
Sheets(1).Cells(sh.Index, 1).Value = sh.Name
Next sh
End Sub

(Note that it's worksheets, which you wanted, chart sheets will not get
listed.

HTH. Best wishes Harald

"glonka " skrev i melding
...
Hi --

I have some workbooks that have 100+ worksheets in them.
I'd like to have a list of the worksheets printed in a worksheet (or
any list of cells).

I found this code on the MSDN:

Private Sub ListSheets()
Dim sh As Excel.Worksheet
Dim rng As Excel.Range
Dim i As Integer

rng = ThisApplication.Range("rangeSheets")
For Each sh In ThisWorkbook.Sheets
rng.Offset(i, 0).Value = sh.Name
i = i + 1
Next sh
End Sub

I created a range of cells called rangeSheets.
This code does not work as is. It must need some
kind of modification that's not obvious.

I have two problems.....
1) I had the remove the word private for it to be visible in the
macros list (OK after that I think)

2) It creates a run time error at this line
rng = ThisApplication.Range("rangeSheets")
I've tried:
set rng = ThisApplication.Range("rangeSheets")
and
rng = ThisApplication.Range("A1")

nothing changes.

Any suggestion how to get a list of worksheets or how to use this
code?

Thanks
Brad


---
Message posted from http://www.ExcelForum.com/







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Get a List of Worksheets

I believe it is VB.NET code. Not VBA.

--
Regards,
Tom Ogilvy


"Harald Staff" wrote in message
...
Thanks. Incredible. That code can't have been tested ever. It should at
least read
Set rng = Range("rangeSheets")
-ranges must be assigned with "Set". And "ThisApplication" is, in this
context, pure nonsense.

Best wishes Harald

"glonka " skrev i melding
...
thanks so much -- that works just fine!!!


Here is the offending URL
http://tinyurl.com/6nlly


---
Message posted from http://www.ExcelForum.com/





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Get a List of Worksheets

Ah. Yes, "Visual Studio Tools for Office 2003". There's Visual Basic and
there's Visual Basic, and I spent much of this summer studying the
differences <blush. Apologies, and thanks.

Best wishes Harald

"Tom Ogilvy" skrev i melding
...
I believe it is VB.NET code. Not VBA.



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
Printing worksheets from a list Paul S Excel Discussion (Misc queries) 0 November 24th 10 07:39 AM
List of worksheets wally New Users to Excel 9 August 31st 08 07:01 PM
Get a list of worksheets from a WB John Scott Excel Discussion (Misc queries) 1 February 26th 06 05:47 PM
how do i list the name off all my worksheets on a sheet tthe Excel Worksheet Functions 6 November 17th 05 08:03 AM
VBA list all worksheets glonka Excel Programming 2 August 10th 04 05:31 PM


All times are GMT +1. The time now is 03:43 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"