Excel打印为PDF到文件夹

huangapple go评论61阅读模式
英文:

Excel Print to PDF to Folder

问题

以下是翻译好的部分:

"Going a bit crazy on this one. Not sure why this code isn't working. My PDF file is saving but its saving to my Documents folder instead of the directed file. It needs to go into this file to save the documentation and I have another code to send an email and attach this file from this directory as well.

Sub PrintPOPDFtoFolder()

ChDir "R:\Procurement\Purchase Orders" & "" 'files directory
fileSaveName = ActiveSheet.Range("Q7") 'Name the PDF file

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
   fileSaveName _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False

            
MsgBox "File Saved " & " " & fileSaveName

End Sub"

英文:

Going a bit crazy on this one. Not sure why this code isn't working. My PDF file is saving but its saving to my Documents folder instead of the directed file. It needs to go into this file to save the documentation and I have another code to send an email and attach this file from this directory as well.

Sub PrintPOPDFtoFolder()

   ChDir "R:\Procurement\Purchase Orders" & "\" 'files directory
   fileSaveName = ActiveSheet.Range("Q7") 'Name the PDF file

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
       fileSaveName _
    , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
    :=False, OpenAfterPublish:=False
    
                
    MsgBox "File Saved " & " " & fileSaveName

End Sub

答案1

得分: 1

不要使用 ChDir,在 ExportAsFixedFormat 调用中使用完整的文件路径:

fileSaveName = "R:\Procurement\Purchase Orders\" & ActiveSheet.Range("Q7").Value
英文:

Instead of relying on ChDir, use the full filepath in the ExportAsFixedFormat call:

fileSaveName = "R:\Procurement\Purchase Orders\" & ActiveSheet.Range("Q7").Value

huangapple
  • 本文由 发表于 2020年1月7日 02:39:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/59617274.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定