为什么可以';Excel 365 vba是否保存我的pdf文件?

为什么可以';Excel 365 vba是否保存我的pdf文件?,excel,vba,office365,Excel,Vba,Office365,我想现在我几乎用尽一切办法用Excel vba保存pdf文件。 这是我的实际代码: Dim pdfFile As String If excel2016 Then pdfFile = Application.DefaultFilePath & "/Report_" & year & month & "_" & Replace(name, " ", "_") & ".pdf" Else pdfFile = ActiveWorkbo


我想现在我几乎用尽一切办法用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

不幸的是,我没有搜索使用Excel 365 VBA保存PDF文件的文章。Wsoutputone是工作表对象?是的,当然这是一个工作表。有人有什么想法可以帮助你吗?你为什么需要这样做?为什么不直接使用工作簿路径呢?谢谢!但不幸的是,您的代码更改仅限于“!ecxel2016”部分。将其与旧的excel版本一起使用是可行的。但是,将它与(某些)excel 365一起使用是行不通的。