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

 ̄綄美尐妖づ 提交于 2019-12-23 04:14:20

问题


I have a folder of ~20 *.potx files and I would like to convert all *.potx files to *.pptx, then delete the *.potx files.


回答1:


The following will loop through all your templates, convert, and delete the template files.

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



回答2:


You could try something like this: (replace YOUR FOLDER HERE with your folder name)

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


来源:https://stackoverflow.com/questions/44528624/how-to-convert-all-potx-files-to-pptx-files-with-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!