【问题标题】:How to convert all *.potx files to *.pptx files with VBA?如何使用 VBA 将所有 *.potx 文件转换为 *.pptx 文件?
【发布时间】:2017-11-15 15:39:50
【问题描述】:

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

【问题讨论】:

  • *.potx 是模板文件,您确定不想从模板中创建新的演示文稿吗?
  • 对我来说,转换为 *.pptx 和创建新的演示文稿听起来是一回事。我正在使用 Adob​​e Writer 将多种文件类型编译为一个 PDF,并且 *.potx 文件无法编译。考虑到其他文件类型,最好将当前 *.potx 文件转换为具有相同文件名的 *.pptx。

标签: vba loops converter powerpoint


【解决方案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

【讨论】:

  • 我收到以下错误:---> 编译错误:未定义用户定义类型
  • 您必须在工具 > 参考下添加对 Microsoft Scripting Runtime 的引用
【解决方案2】:

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

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

【讨论】:

  • Kill sFolder & "\" & sFilepApp.ActivePresentation.Close 之后删除文件。
猜你喜欢
  • 1970-01-01
  • 2012-09-20
  • 2011-09-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-07-27
  • 1970-01-01
  • 2018-01-01
相关资源
最近更新 更多