Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default Find Chart Sheets in workbook

I am trying to loop through the sheets in a workbook and test to see if the
which sheets are chart sheets. The code is failing is this because of the
way I have set up the wrksht variable (i.e. dim as worksheet)?

Function IsChartSheet() As Boolean
Dim wrksht As Worksheet
Dim chrtsht As Chart
On Error Resume Next

For Each wrksht In ThisWorkbook
Set chrtsht = ActiveWorkbook.Charts(wrksht.Name)
If Err = 0 Then
IsChartSheet = True
Debug.Print ActiveSheet.Name
Debug.Print "This is a chart sheet!"
Else
IsChartSheet = False
Debug.Print ActiveSheet.Name
Debug.Print "This is not a chart sheet!"
End If
On Error GoTo 0
Set chrtsht = Nothing
Next
End Function


Thanks

EM
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Find Chart Sheets in workbook

Worksheets can't be chart sheets.

maybe you could use:

Dim sht as Object
for each sht in thisworkbook.sheets
msgbox typename(sht)
next sht

So you can test it for:

if typename(sht) = "Chart" then
'it's a chart sheet.
end if

Be careful. There are other types of sheets besides worksheets and chart
sheets.



ExcelMonkey wrote:

I am trying to loop through the sheets in a workbook and test to see if the
which sheets are chart sheets. The code is failing is this because of the
way I have set up the wrksht variable (i.e. dim as worksheet)?

Function IsChartSheet() As Boolean
Dim wrksht As Worksheet
Dim chrtsht As Chart
On Error Resume Next

For Each wrksht In ThisWorkbook
Set chrtsht = ActiveWorkbook.Charts(wrksht.Name)
If Err = 0 Then
IsChartSheet = True
Debug.Print ActiveSheet.Name
Debug.Print "This is a chart sheet!"
Else
IsChartSheet = False
Debug.Print ActiveSheet.Name
Debug.Print "This is not a chart sheet!"
End If
On Error GoTo 0
Set chrtsht = Nothing
Next
End Function

Thanks

EM


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Find Chart Sheets in workbook

If you wanted to get the chart sheets, you could use this:

Dim Cht as Chart
For Each Cht In ActiveWorkbook.Charts
' Cht is a chart sheet
Next

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Dave Peterson" wrote in message
...
Worksheets can't be chart sheets.

maybe you could use:

Dim sht as Object
for each sht in thisworkbook.sheets
msgbox typename(sht)
next sht

So you can test it for:

if typename(sht) = "Chart" then
'it's a chart sheet.
end if

Be careful. There are other types of sheets besides worksheets and chart
sheets.



ExcelMonkey wrote:

I am trying to loop through the sheets in a workbook and test to see if
the
which sheets are chart sheets. The code is failing is this because of
the
way I have set up the wrksht variable (i.e. dim as worksheet)?

Function IsChartSheet() As Boolean
Dim wrksht As Worksheet
Dim chrtsht As Chart
On Error Resume Next

For Each wrksht In ThisWorkbook
Set chrtsht = ActiveWorkbook.Charts(wrksht.Name)
If Err = 0 Then
IsChartSheet = True
Debug.Print ActiveSheet.Name
Debug.Print "This is a chart sheet!"
Else
IsChartSheet = False
Debug.Print ActiveSheet.Name
Debug.Print "This is not a chart sheet!"
End If
On Error GoTo 0
Set chrtsht = Nothing
Next
End Function

Thanks

EM


--

Dave Peterson



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
copy chart between multiple sheets in workbook Sam Charts and Charting in Excel 4 March 12th 10 03:59 PM
Find exact match, same workbook, different sheets dmshurley Excel Discussion (Misc queries) 2 September 19th 07 03:02 AM
Find from just certain sheets in a workbook Blondegirl Excel Programming 4 April 13th 06 12:18 PM
Find / Replace sheets vs workbook in VB Bony Pony Excel Worksheet Functions 0 December 8th 04 02:21 PM
How to find the type of Sheet in Excel.Workbook.sheets collection Raj[_7_] Excel Programming 3 December 9th 03 10:48 PM


All times are GMT +1. The time now is 02:26 AM.

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"