如何使用vba将Excel中的多个图形导出为单个pdf? [英] How can I export multiple graphs from excel to a single pdf using vba?

查看:707
本文介绍了如何使用vba将Excel中的多个图形导出为单个pdf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全是VBA新手,需要使用vba将excel工作簿中的多个图形导出到一个pdf中。我知道有可能将图形导出为单独的pdf或jpg,但是是否可能将工作簿中的所有图形使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆