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
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

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
 

Forum statistics

Threads
1,141,138
Messages
5,704,497
Members
421,353
Latest member
jekoxien15

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top