Sub SELLSHEETUPDATES_Macro()
Dim oPPTApp As PowerPoint.Application
Dim oPPTFile As PowerPoint.Presentation
Dim onlyFileName As String, folderPath As String, pptFiles As String, removeFileExt As Long
Application.ScreenUpdating = False
folderPath = Range("C5").Text & ""
pptFiles = Dir(folderPath & "*.pp*")
If pptFiles = "" Then
MsgBox "No files found"
Exit Sub
End If
Do While pptFiles \<\> ""
Set oPPTApp = CreateObject("PowerPoint.Application")
oPPTApp.Visible = msoTrue
On Error Resume Next
Set oPPTFile = oPPTApp.Presentations.Open(folderPath & pptFiles)
On Error GoTo 0
removeFileExt = InStr(1, oPPTFile.Name, ".") - 1
onlyFileName = Left(oPPTFile.Name, removeFileExt)
On Error Resume Next
oPPTFile.ExportAsFixedFormat oPPTFile.Path & "" & onlyFileName & ".pdf", ppFixedFormatTypePDF, ppFixedFormatIntentPrint
oPPTFile.Close
pptFiles = Dir()
Loop
oPPTApp.Quit
Set oPPTFile = Nothing
Set oPPTApp = Nothing
Application.ScreenUpdating = True
MsgBox " Successfully converted"
End Sub
Sub SELLSHEETUPDATES()
End Sub
粗体是突出显示错误的地方
我不编写代码,但我在谷歌上搜索了这段代码,试图尝试将一个文件夹中的所有 PowerPoint 转换为单独保存的 PDF 文件副本。这是为了减少打开每个 PowerPoint 文件并将副本另存为 PDF 文件的工作时间。
ppFixedFormatTypePDF 和 ppFixedFormatIntentPrint 都是 PowerPoint 定义的常量; Excel 不知道它们是什么,因此会出现错误消息。
要么对它们都使用 2,要么在模块顶部将它们都定义为常量(如 Long = 2)。
Do While pptFiles <> "" 应该是 Do While pptFiles <> "" 或更好, 当 Len(pptFiles) = 0 时执行
此外,您每次通过循环都会创建 PPT 应用程序对象,但在退出循环之前不会释放它。在循环开始之前创建对象。
最后,你的代码有点像 ChatGPT arfs 的东西。它似乎想要在 Excel 中完成所有工作,即使您要求在 PPT 中完成更简单的事情。除了在 Excel 的单元格中包含文件夹名称之外,这样做还有其他特殊价值吗?