Problem with Code

MarkAndrews

Well-known Member
Joined
May 2, 2006
Messages
1,970
Office Version
  1. 2010
Platform
  1. Windows
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

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
try

Code:
For Each cht In ThisWorkbook.Charts

you must always have the collection in the For statement
 
Upvote 0
Excellent, Thanks v much guys!

You've saved my *** again!
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,618
Members
449,092
Latest member
amyap

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
Back
Top