Managing Excel charts using VBA is always a bit confusing because there are ChartObject and then there are Chart objects. Each ChartObject has a child Chart . It is not always very intuitive which properties and methods belong to Chart and which should be found in its parent ChartObject . Quoting VBA Help:
[ ChartObject ] represents an inline chart in a worksheet. The ChartObject acts as a container for the Chart . The properties and methods of the ChartObject object control the appearance and size of the inline chart on the sheet.
Reading VBA help can get you nuts if you donโt have glasses, because ChartObject means something other than a Chart object!
Anyway, as it turned out, .PageSetup.Orientation is on Chart , not ChartObject , as you concluded.
Dim wks As Worksheet Dim chartObject As ChartObject For Each wks In ActiveWorkbook.Worksheets For Each chartObject In wks.ChartObjects .Chart.PageSetup.Orientation = xlLandscape ' or xlPortrait .Chart.PrintOut Preview:=True, ActivePrinter:="PDFCreator" Next Next
It is assumed that you want to print each chart on a separate page. What you did in your code was to print each worksheet at once, but that doesn't look like the rest of your question.
Here I used PDFCreator as my printer because I didnโt want to spend a ton of paper while testing this code. You can, of course, customize this as you see fit.
I also install an active printer while printing. Of course, you can also use Application.ActivePrinter , but this will affect the active printer, even when the macro is run.
source share