【问题标题】:save sheet pdf excel vba保存工作表 pdf excel vba
【发布时间】:2020-12-13 08:30:59
【问题描述】:

我有以下 vba 代码

Sub SaveAsPDF()
Dim FileAndLocation As Variant
Dim strPathLocation As String
Dim strFilename As String
Dim strPathFile As String

strPathLocation = Worksheets("Sheet1").Range("A2").Value
strFilename = Worksheets("Sheet1").Range("A4").Value
strPathFile = strPathLocation & strFilename
Sheets("Sheet2").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
strPathLocation & strFilename & ".pdf" _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
End Sub

我想要实现的是将Sheet2作为pdf保存到指定的路径和指定的文件名

【问题讨论】:

  • 有什么问题/错误? strPathLocation的末尾有路径分隔符吗?
  • 我遇到运行时错误,当我将 Sheet2 调试到 vba 末尾时以黄色突出显示
  • 错误信息是?
  • 确保Debug.Print strPathLocation & strFilename & "pdf" - 很可能它缺少路径分隔符。
  • 您没有包含fPath - 您只有FileName:=fName。最有可能应该是FileName:=fPath & Application.PathSeparator & fName

标签: excel vba


【解决方案1】:

试试看。

在 vba 中选择您的工作表并使用此函数导出,您可以在函数中作为参数传递的文件名。

Sub ExportarPDF()

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="yourpath.pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-11
    相关资源
    最近更新 更多