英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论