VBA ExportAsFixedFormat only saves last active chart
I am trying to save one worksheet from a book as a pdf using the ExportAsFixedFormat method:
Sheets("Overview").ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=Mid(saveFile, 1, InStr(saveFile, ".")) & "pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
This worked for a while until I started doing some chart manipulation beforehand. The manipulation I'm talking about looks like this:
ActiveSheet.ChartObjects("Diagramm 4").Activate
ActiveChart.SetSourceData Source:=Sheets("Measurements").Range( _
"C4:C29,G4:G29")
Now it does not export the entire sheet as PDF, but rather just a chart called "Chart 4". I more or less understand why it does this, but I can't seem to find a way to fix it.
+3
source to share
1 answer
You can try to select any cell in this sheet, for example:
Range("A1").Select
before exporting the page. This is probably because you are making the chart active without making it inactive again. See what happens when you normally select a graph and then try to print the worksheet - it will just try to print the chart.
+2
source to share