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

时间:2017-06-13 18:08:34

标签: vba loops converter powerpoint

我有~20 * .potx文件的文件夹,我想将所有* .potx文件转换为* .pptx,然后删除* .potx文件。

2 个答案:

答案 0 :(得分:1)

你可以尝试这样的事情:(用你的文件夹名称替换你的文件夹)

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

答案 1 :(得分:1)

以下内容将遍历所有模板,转换和删除模板文件。

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