如何使用VBA将所有*.potx文件转换为*.pptx文件?

How to convert all *.potx files to *.pptx files with VBA?

我有一个包含约 20 个 *.potx 文件的文件夹,我想将所有 *.potx 文件转换为 *.pptx,然后删除 *.potx 文件。

您可以尝试这样的操作:(将 YOUR FOLDER HERE 替换为您的文件夹名称)

Public Sub ConvertPP()
  Dim pApp As Object
  Set pApp = CreateObject("Powerpoint.Application")
  Dim sFile As String
  Dim sFolder As String
  sFolder = "YOUR FOLDER HERE"

  sFile = Dir(sFolder & "\*.potx")
  Do Until sFolder = ""
    pApp.Presentations.Open sFolder & "\" & sFile
    pApp.ActivePresentation.SaveAs sFolder & "\" & Replace(sFile, "potx", "pptx"), 11
    pApp.ActivePresentation.Close
    sFile = Dir()
  Loop
  pApp.Quit
  Set pApp = Nothing
End Sub

以下将循环遍历您的所有模板、转换和删除模板文件。

Sub loopFiles()

    Dim fso As New FileSystemObject
    Dim fil As File
    Dim fold As Folder

    Set fold = fso.GetFolder(yourFolder)

    For Each fil In fold.Files

        If InStr(1, fil.Name, ".potx") > 0 Then
            Application.Presentations.Open fil.Path
            ActivePresentation.SaveAs Replace(fil.Path, ".potx", ".pptx"), ppSaveAsDefault
            ActivePresentation.Close

            'if you truly want to delete them, don't recommend since they are .potx
            fil.Delete True
        End If

    Next fil

End Sub