[英]Why can't Excel 365 vba save my pdf file?
我想現在我嘗試了幾乎所有方法來使用 Excel vba 保存 pdf 文件。
這是我的實際代碼:
Dim pdfFile As String
If excel2016 Then
pdfFile = Application.DefaultFilePath & "/Report_" & year & month & "_" & Replace(name, " ", "_") & ".pdf"
Else
pdfFile = ActiveWorkbook.Path & Application.PathSeparator & "Report_" & year & month & "_" & Replace(name, " ", "_") & ".pdf"
End If
wsOutputOne.ExportAsFixedFormat Type:=xlTypePDF, fileName:=pdfFile
我知道 Excel 2016 正在創建一個“容器”並將文件保存在~/Library/Containers/com.microsoft.Excel/Data/Documents/
但為什么該代碼不適用於 Excel 365?
或者使用 Excel 365 的朋友如何保存生成的 pdf 文件?
因為Application.DefaultFilePath
的調用在他的機器上沒有返回任何東西......
有人可以幫助我嗎?
請嘗試以下代碼:
Dim pdfFile As String
If excel2016 Then
pdfFile = Application.DefaultFilePath & "/Report_" & year & month & "_" & Replace(name, " ", "_") & ".pdf"
Else
pdfFile = Application.ActiveWorkbook.Path & Application.PathSeparator & "Report_" & year & month & "_" & Replace(name, " ", "_") & ".pdf"
End If
wsOutputOne.ExportAsFixedFormat Type:=xlTypePDF, fileName:=pdfFile
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.