PowerPoint 中单个拆分文件的文件名

Posted

技术标签:

【中文标题】PowerPoint 中单个拆分文件的文件名【英文标题】:Filename of individual split files in PowerPoint 【发布时间】:2014-12-16 09:19:29 【问题描述】:

那里

我在使用 MS PowerPoint 时遇到问题。我目前正在处理大约十几个文件,每个文件至少有 100 张幻灯片。我需要创建单独的幻灯片作为单独的文件以供上传。我有一个代码可以将文件拆分为单独的幻灯片。查询是如何使用 VBA 代码自动重命名这些文件?

每张幻灯片在文本框中都有一个标题,标题文本框的形状和大小在所有幻灯片中都是一致的。如何确保创建的单个文件以“幻灯片标题”作为文件名保存?

截至目前,该文件保存为“原始文件名。n-n

非常感谢您在这方面的帮助。

以下是我在互联网上找到的将幻灯片分成多个单独文件的代码(我的目的是每张幻灯片):

Sub SplitFile()

    Dim lSlidesPerFile As Long
    Dim lTotalSlides As Long
    Dim oSourcePres As Presentation
    Dim otargetPres As Presentation
    Dim sFolder As String
    Dim sExt As String
    Dim sBaseName As String
    Dim lCounter As Long
    Dim lPresentationsCount As Long     ' how many will we split it into
    Dim x As Long
    Dim lWindowStart As Long
    Dim lWindowEnd As Long
    Dim sSplitPresName As String

    On Error GoTo ErrorHandler

    Set oSourcePres = ActivePresentation
    If Not oSourcePres.Saved Then
        MsgBox "Please save your presentation then try again"
        Exit Sub
    End If

    lSlidesPerFile = CLng(InputBox("How many slides per file?", "Split Presentation"))
    lTotalSlides = oSourcePres.Slides.Count
    sFolder = ActivePresentation.Path & "\"
    sExt = Mid$(ActivePresentation.Name, InStr(ActivePresentation.Name, ".") + 1)
    sBaseName = Mid$(ActivePresentation.Name, 1, InStr(ActivePresentation.Name, ".") - 1)

    If (lTotalSlides / lSlidesPerFile) - (lTotalSlides \ lSlidesPerFile) > 0 Then
        lPresentationsCount = lTotalSlides \ lSlidesPerFile + 1
    Else
        lPresentationsCount = lTotalSlides \ lSlidesPerFile
    End If

    If Not lTotalSlides > lSlidesPerFile Then
        MsgBox "There are fewer than " & CStr(lSlidesPerFile) & " slides in this presentation."
        Exit Sub
    End If

    For lCounter = 1 To lPresentationsCount

        ' which slides will we leave in the presentation?
        lWindowEnd = lSlidesPerFile * lCounter
        If lWindowEnd > oSourcePres.Slides.Count Then
            ' odd number of leftover slides in last presentation
            lWindowEnd = oSourcePres.Slides.Count
            lWindowStart = ((oSourcePres.Slides.Count \ lSlidesPerFile) * lSlidesPerFile) + 1
        Else
            lWindowStart = lWindowEnd - lSlidesPerFile + 1
        End If

        ' Make a copy of the presentation and open it
        sSplitPresName = sFolder & sBaseName & _
               "_" & CStr(lWindowStart) & "-" & CStr(lWindowEnd) & "." & sExt
        oSourcePres.SaveCopyAs sSplitPresName, ppSaveAsDefault
        Set otargetPres = Presentations.Open(sSplitPresName, , , True)

        With otargetPres
            For x = .Slides.Count To lWindowEnd + 1 Step -1
                .Slides(x).Delete
            Next
            For x = lWindowStart - 1 To 1 Step -1
                .Slides(x).Delete
            Next
            .Save
            .Close
        End With

    Next    ' lpresentationscount

NormalExit:
    Exit Sub
ErrorHandler:
    MsgBox "Error encountered"
    Resume NormalExit
End Sub

【问题讨论】:

【参考方案1】:

这将让它从标题中提取文本并将其用作输出演示名称:

sSplitPresName = sFolder _
  & oSourcePres.Slides(lWindowStart).Shapes.Title.TextFrame.TextRange.Text _
  & "." & sExt

如果幻灯片没有标题,您会收到错误消息,因此您需要对此进行测试并决定在这种情况下如何命名拆分的演示文稿。也许:

sSplitPresName = sFolder _
  & "Slide-" & Cstr(lWindowStart) _
  & "." & sExt

您还希望通过一个函数来运行幻灯片标题,该函数可以删除在查看演示文稿的操作系统中作为文件名无效的任何字符。

【讨论】:

以上是关于PowerPoint 中单个拆分文件的文件名的主要内容,如果未能解决你的问题,请参考以下文章

text 如何从保存在多个文件中的幻灯片快速编译单个PowerPoint演示文稿?

Vue 将组件从单个 .js 文件拆分到多个文件中

使用 Python 将内容从单个文件夹拆分到多个子文件夹

VBA 实例:拆分每个工作表为单个文件

拆分火鸟数据库文件

Django,当单个模型变大时模型拆分?