簡體   English   中英

如何使用VBA將所有* .potx文件轉換為* .pptx文件?

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

我有一個約20個* .potx文件的文件夾,我想將所有* .potx文件轉換為* .pptx,然后刪除* .potx文件。

您可以嘗試執行以下操作:(在此處用您的文件夾名稱替換您的文件夾)

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM