Problem with Code

MarkAndrews

Well-known Member
Joined
May 2, 2006
Messages
1,963
I have the following code in place (Workbook_BeforeClose)

However - It does not like the following line

' get the chart sheets
For Each cht In ThisWorkbook

There are 18 charts in this workbook - Any Idea's?

TIA

Rich (BB code):
Sub PrintAllCharts()
    
  Application.ScreenUpdating = False
  Dim ws As Worksheet
  Dim chob As ChartObject
  Dim cht As Chart
  Dim vbAns As Long

  vbAns = MsgBox("Do you want to print all charts?", vbQuestion + vbYesNo)
  
  If vbAns <> vbYes Then GoTo ExitSub

  ' get the chart sheets
  For Each cht In ThisWorkbook
    cht.PrintOut
    ' get any charts embedded in the chart sheet
    For Each chob In cht.ChartObjects
      chob.Chart.PrintOut
      DoEvents
    Next
  Next
  
  ' now get all charts embedded on all worksheets
  For Each ws In ThisWorkbook.Worksheets
    For Each chob In ws.ChartObjects
      chob.Chart.PrintOut
      DoEvents
    Next
  Next
  
ExitSub:
  Application.ScreenUpdating = True
  End Sub
 

Some videos you may like

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

lozzablake

Well-known Member
Joined
Dec 15, 2005
Messages
818
try

Code:
For Each cht In ThisWorkbook.Charts

you must always have the collection in the For statement
 

Watch MrExcel Video

Forum statistics

Threads
1,109,461
Messages
5,528,935
Members
409,847
Latest member
Foster034
Top