【问题标题】:store excel sheet as PDF on desktop在桌面上将 Excel 工作表存储为 PDF
【发布时间】:2014-11-07 12:51:35
【问题描述】:

我有以下代码将工作表存储为 PDF。我想控制它的存储位置——即他们的桌面。有人可以给我一个提示如何做到这一点。谢谢!

Sub SaveAsPDF()
Dim i As Long
Dim PdfFile As String, Title As String

' Not sure for what the Title is
Title = Range("B1")

' Define PDF filename
PdfFile = Range("F3")
i = InStrRev(PdfFile, ".")
If i > 1 Then PdfFile = Left(PdfFile, i - 1)
PdfFile = PdfFile & ".pdf"

' Export activesheet as PDF
With ActiveSheet
  .ExportAsFixedFormat Type:=xlTypePDF, Filename:=PdfFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End With

End Sub

【问题讨论】:

    标签: excel pdf vba


    【解决方案1】:

    如果您总是想在没有任何用户干预的情况下保存到桌面:

    PdfFile = createobject("Wscript.Shell").Specialfolders("Desktop") & "\" & PdfFile & ".pdf"
    

    【讨论】:

    • + 1 准确回答 OP 正在寻找的内容 :)
    【解决方案2】:

    Rory 的答案的替代方法是使用 Windows 环境变量“userprofile”

    PdfFile = Environ("userprofile") & "\desktop\" & PdfFile & ".pdf"
    

    【讨论】:

    • 非常感谢罗里和安德烈亚斯!适用于 Windows。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-22
    • 1970-01-01
    • 1970-01-01
    • 2015-08-18
    • 1970-01-01
    • 2014-02-10
    • 1970-01-01
    相关资源
    最近更新 更多