如何使用vba将Excel中的多个图形导出为单个pdf? [英] How can I export multiple graphs from excel to a single pdf using vba?
问题描述
我的代码到目前为止,将每个图表打印到pdf,但每个图表将在下一次打印时被覆盖。我的代码如下:
Sub exportGraphs()
Dim Ws As Worksheet
Dim Filename As String
Filename = Application.InputBox(输入pdf文件名,类型:= 2)
表(状态和SLA趋势)。选择
ActiveSheet.ChartObjects(图4 ).Activate
ActiveChart.ExportAsFixedFormat xlTypePDF,Filename,xlQualityStandard
ActiveSheet.ChartObjects(Chart 1)。激活
ActiveChart.ExportAsFixedFormat xlTypePDF,Filename,xlQualityStandard
选择
ActiveSheet.ChartObjects(Chart 2)。激活
ActiveChart.ExportAsFixedFormat xlTypePDF,Filename,xlQualityStandard
ActiveSheet.ChartObjects(Chart 5) .Activate
ActiveChart.ExportAsFixedFormat xlTypePDF,Filename,xlQualityStandard
ActiveSheet.ChartObjects(Chart 8)。激活
ActiveChart.ExportAsFixedFormat xlTypePDF,Filename,xlQualityStandard
End Sub
我最后,我刚刚导出了一组表格到pdf,因为多个图表在不同的表格,我不需要改变他们的格式。我使用以下代码片段
表格(Array(当前问题状态,状态和SLA趋势)) 。选择
Dim saveLocation As String
saveLocation = Application.GetSaveAsFilename(_
fileFilter:=PDF文件(* .pdf),* .pdf)
如果saveLocation< > False然后
ActiveSheet.ExportAsFixedFormat xlTypePDF,saveLocation,xlQualityStandard
End If
I am completely new to VBA and need to export multiple graphs from an excel workbook to a single pdf using vba. I know it's possible to export the graphs as individual pdf's or jpgs but is it possibly to put all graphs from a workbook into one pdf using vba? Any advice would be greatly appreciated as I can't seem to find what I'm looking for elsewhere.
My code so far prints each chart to the pdf, but each chart gets overwritten on the next print. My code is as follows:
Sub exportGraphs()
Dim Ws As Worksheet
Dim Filename As String
Filename = Application.InputBox("Enter the pdf file name", Type:=2)
Sheets("Status and SLA trends").Select
ActiveSheet.ChartObjects("Chart 4").Activate
ActiveChart.ExportAsFixedFormat xlTypePDF, Filename, xlQualityStandard
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ExportAsFixedFormat xlTypePDF, Filename, xlQualityStandard
Sheets("Current Issue Status").Select
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.ExportAsFixedFormat xlTypePDF, Filename, xlQualityStandard
ActiveSheet.ChartObjects("Chart 5").Activate
ActiveChart.ExportAsFixedFormat xlTypePDF, Filename, xlQualityStandard
ActiveSheet.ChartObjects("Chart 8").Activate
ActiveChart.ExportAsFixedFormat xlTypePDF, Filename, xlQualityStandard
End Sub
In the end I just exported an array of sheets to pdf, as multiple charts were on separate sheets and I didn't need to change how they were formatted. I did it using the following code snippet
Sheets(Array("Current Issue Status", "Status and SLA trends")).Select
Dim saveLocation As String
saveLocation = Application.GetSaveAsFilename( _
fileFilter:="PDF Files (*.pdf), *.pdf")
If saveLocation <> "False" Then
ActiveSheet.ExportAsFixedFormat xlTypePDF, saveLocation, xlQualityStandard
End If
这篇关于如何使用vba将Excel中的多个图形导出为单个pdf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!