PowerPoint:手动设置幻灯片名称

11

背景: 在C#中的PowerPoint幻灯片中,有一个属性Slide.Name(通常包含任意字符串值)。我想在我的C#应用程序中使用此属性来标识幻灯片(幻灯片顺序不可靠)。

问题: 如何手动设置PowerPoint应用程序中的Slide.Name属性?

我的问题非常类似于“如何在PowerPoint幻灯片内命名对象?”,但仅适用于幻灯片级别。

任何帮助将不胜感激。

6个回答

14

在PowerPoint中,没有内置的功能可以编辑幻灯片的名称。正如Steve所提到的,您必须使用VBA代码进行操作。插入更多幻灯片不会更改幻灯片名称;即使关闭了PowerPoint,幻灯片名称设置在VBA代码中也是持久的。下面是我编写的一些代码,可以让您轻松查看当前选定幻灯片的名称并将其重命名:

'------------------------------------------------------------------
' NameSlide()
'
' Renames the current slide so you can refer to this slide in
' VBA by name. This is not used as part of the application;
' it is for maintenance and for use only by developers of
' the PowerPoint presentation.
'
' 1. In Normal view, click on the slide you wish to rename
' 2. ALT+F11 to VB Editor
' 3. F5 to run this subroutine
'------------------------------------------------------------------
Sub NameSlide()
    Dim curName As String
    curName = Application.ActiveWindow.View.Slide.name
    
    Dim newName As String
retry:
    newName = InputBox("Enter the new name for slide '" + curName + "', or press Cancel to keep existing name.", "Rename slide")
    If Trim(newName) = "" Then Exit Sub
            
    Dim s As Slide
    
    ' check if this slide name already exists
    On Error GoTo SlideNotFound
    Set s = ActivePresentation.Slides(newName)
    On Error GoTo 0
    
    MsgBox "Slide with this name already exists!"
    GoTo retry
    
    Exit Sub
    
SlideNotFound:
    On Error GoTo 0
    Application.ActiveWindow.View.Slide.name = newName
    MsgBox "Slide renamed to '" + newName + "'."
        
End Sub

这个脚本对于VBA编程非常有用:它可以让你重命名任何幻灯片,以便你可以在VBA代码中可靠地使用幻灯片名称。 - Kar.ma

6

您无法手动设置幻灯片名称,但通过一些代码,这很简单。例如,在VBA中:

Sub NameThatSlide()
  ActivePresentation.Slides(1).Name = "Whatever You Like Here"
End Sub

这将有效地更改Slide Presentation Edit窗口中幻灯片的名称。但是,在VBA编辑器中,幻灯片仍然显示为它们的原始名称,例如“ Slide1”和“ Slide32”等,已删除的幻灯片之间存在间隙。是否有办法让VBAProject“ Microsoft PowerPoint Object”列表中显示的名称与幻灯片的.Name属性相一致(在PowerPoint 2013中)? - DRC
我不相信有这样的功能。PowerPoint在创建每个幻灯片时都会为其命名。每个幻灯片还具有一个.Name属性,PPT最初将其设置为与幻灯片名称相同的字符串。当我们设置.Name时,它是这个.Name属性而不是幻灯片的内部名称发生变化。通过编辑演示文稿XML,可能可以更改内部名称。我很好奇:更改名称的需要是什么? - Steve Rindsberg
感谢您的回复,@Steve Rindsberg。我需要在VBA中轻松编程。我有一个“演示文稿”,它将成为学生的培训工具。它将完全由VBA控制,因此VBA代码控制何时允许学生继续到下一张幻灯片等。由于我重新排列了幻灯片的顺序并创建了大量的“测试”幻灯片,在编辑视图中使用幻灯片名称很明智,但切换到VBAProject视图后,幻灯片只有一个数字,与编辑视图中的名称不符,这很令人困惑。 - DRC
如果涉及控制学生在幻灯片上单击按钮时发生的事情,您最好使用常规形状,而不是ActiveX组件,并将其分配给Run Macro操作设置。如果您从Sub RunMe(oSh as Shape)之类的东西开始宏,您将在oSh中获得对所单击形状的引用。然后,oSh.Parent会为您提供对形状所在幻灯片的引用。您几乎总是可以以这样的方式编写代码,而无需为每个ActiveX形状维护不同的代码批次。而且这更可靠。 - Steve Rindsberg
再次感谢@Steve Rindsberg。我应该听取您的建议!问题是,代码相当复杂,例如每次运行演示文稿时更改多项选择项目的顺序,在代码中轻松重新编写项目而不是在形状中,因为不同的形状每次运行都会有不同的答案,使用文本到语音和语音标记语言的代码,重新呈现回答错误的幻灯片等。因此,我希望幻灯片名称与幻灯片.name属性匹配! - DRC

3
你可以手动或使用VBA重命名幻灯片。一旦你知道如何操作,就可以展示一些有趣的功能,下面我将用代码进行演示。
手动重命名幻灯片。此功能隐藏在VBA编辑器的属性窗格中,但不需要编码。
1. 如果开发者选项卡不可见,请启用它:[文件] > [选项] > [自定义功能区] > 选中 [开发者] 主选项卡。 2. 点击“开发人员”选项卡,然后点击“Visual Basic”菜单项以打开Visual Basic编辑器。 3. 按Ctrl+R键导航到项目资源管理器窗格。 4. 展开“Microsoft PowerPoint Objects”。 5. 单击任何一个幻灯片以选择它。 6. 按F4键导航到属性窗格。 7. 编辑“(Name)”项,并按Enter键应用名称更改。
幻灯片名称更改可能不会立即出现在VBA项目资源管理器窗格中。只要属性窗格中的名称正确,名称更改就成功了。
这段VBA代码也能实现相同效果(隐藏第一张幻灯片):
ActivePresentation.Slides(1).SlideShowTransition.Hidden = msoTrue

此代码块介绍了几种管理幻灯片名称的方法,并回答了主要问题。
Option Explicit

Public Function RenameSlide(oldName As String, newName As String)
' RenameSlide finds slide oldName and renames it to newName.
' Arguements:
'   oldName: current (old) name of existing slide
'   newName: new name for slide.
'
    Dim tempBool As Boolean
    Dim sld As Slide
    Dim RetVal(0 To 1) As String

    ' Check if oldName can be found.
    If SlideExists(oldName) Then
        Set sld = Application.ActivePresentation.Slides(oldName)
    Else
        RetVal(0) = 1 'Error 1
        RetVal(1) = "Error 1: slide with name " & oldName & " not found. Aborting."
        Exit Function
    End If

    ' Check if this slide name newName already exists.
    If SlideExists(newName) Then
        RetVal(0) = 2 'Error 1
        RetVal(1) = "Error 2: slide with name " & newName & " already exists. Aborting."
        Exit Function
    End If

    ' Rename the slide
    'Application.ActivePresentation.Slides(oldName) = newName
    Application.ActivePresentation.Slides(oldName).Select
    Application.ActiveWindow.View.Slide.Name = newName 'current slide
    RetVal(0) = 0 'Success
    RetVal(1) = "Success: slide renamed from '" & oldName & "' to '" & newName & "'."

End Function

Public Sub SetSlideName()
' Prompt user for new name for active slide.
'
    Dim oldName As String
    Dim newName As String
    Dim sld As Slide
    Dim msg As String

    ' Get current name of active slide.
    oldName = Application.ActiveWindow.View.Slide.Name

    msg = "Enter the new name for slide '" + oldName + "'."
retry:
    newName = ""
    ' Prompt for new slide name. Loop until a name of at least 1 character is provided.
    Do While newName = ""
        newName = InputBox(msg, "Rename slide")
        newName = Trim(newName)
        If Len(newName) = 0 Then
            msg = "Try again.  You must enter a slide name to continue."
        ElseIf newName = oldName Or newName = Str(vbCancel) Then
            Exit Sub
        End If
    Loop

    ' If an existing slide already has name newName, then
    ' go back and prompt user again.slide name already exists
    If SlideExists(newName) Then
        msg = "Slide with this name already exists!"
        GoTo retry
    End If

    ' Set the new slide name
    Application.ActiveWindow.View.Slide.Name = newName
    MsgBox "Slide renamed to '" + newName + "'."
End Sub

Public Function SlideExists(SlideName As String) As Boolean
    Dim RetVal As Boolean
    Dim sld

    ' Assume slide does not exist.
    SlideExists = False

    ' Try to find slide by name.
    ' If we error out, the slide does NOT exist.
    On Error GoTo NoSlide
    Set sld = ActivePresentation.Slides(SlideName)

    ' If we got this far, the slide DOES exist.
    SlideExists = True
    Exit Function

NoSlide:
    ' Error setting slide objects shows
    ' that slides does NOT exist.
    SlideExists = False
End Function

作为旁注,我使用幻灯片命名技巧和一些VBA代码来选择性地移除打印某些幻灯片。我添加了一些额外的VBA宏,以便填充宏列表。从任何幻灯片开始:开发人员选项卡>宏>选择宏>运行按钮。使用这种方法启动我的PresentSlide、DontPresentSlide、PrintSlide和DontPrintSlide宏。一旦你正确地标记了各个幻灯片,只需在展示或打印之前运行PrepToPresentSlides或PrepToPrintSlides宏即可。
请尝试使用这些宏并阅读注释。你会发现,我编写的代码是可扩展的,因此你可以轻松地根据自己的需要进行修改。
下面的代码帮助我管理打印哪些幻灯片和对象,以及呈现哪些幻灯片和对象。当我想打印参考幻灯片但不想覆盖它们时,这尤其有用。当我有带有动画的幻灯片时,这更加有用。动画通常不适合打印。因此,我选择完全不打印某些动画对象。实际上,我甚至可以添加替代内容,仅用于打印(在展示时隐藏)-虽然我很少这样做。相反,我通常会将动画从打印中隐藏,或者创建一个幻灯片来呈现和一个非动画副本用于打印。有了这些宏,很容易管理打印需要混合匹配的幻灯片和对象以及展示需要混合匹配的幻灯片和对象。希望你喜欢。
Option Explicit

' DontPresentSlide - run macro while on a slide you wish to skip while presenting.
'                    The slide name will be appended with "NoPresent". You still
'                    need to run PrepToPresent before presenting to hide slide.
' PresentSlide - "NoPresent" will be removed from the slide. You still
'                need to run PrepToPresent before presenting to hide slide.
' PrepToPesentSlides() - Unhide slides and objects you want presented and
'                hide slides and objects you do NOT want presented.
' ShowNoPressnt() - show slides and shapes marked "NoPresent"
' HideNoPresent() - hide slides and shapes marked "NoPresent"

' DontPrintSlide - run macro while on a slide you wish to skip while presenting.
'                    The slide name will be appended with "NoPrint". You still
'                    need to run PrepToPresent before presenting to hide slide.
' PrintSlide - "NoPrint" will be removed from the slide. You still
'                need to run PrepToPresent before presenting to hide slide.
' PrepToPrintSlides() - Unhide slides and objects you want printed and
'                hide slides and objects you do NOT want printed.
' ShowNoPrint() - show slides and shapes marked "NoPrint"
' HideNoPrint() - hide slides and shapes marked "NoPrint"

' ShowHideSlides() - Hide or Unhide slides based on slide name.
' ShowHideShapes() - Hide or Unhide shapes based on shapes name.


Public Const cjaHide = False
Public Const cjaShow = True
Public Const cjaToggle = 2

Sub ShowHideSlides(NameContains As String _
                , Optional LMR As String = "R" _
                , Optional ShowSlide As Integer = False)
' Show or Hide slides based on slide name.
' Arguements:
'   NameContains (string):
'       slides with this string will be modified.
'   LMR (string): enter L, M or R to indicate
'       searching the Left, Middle or Right of
'       the slide name, respectively.
'   ShowSlide (integer):
'       Show: True (-1)
'       Hide: False (0)
'       Toggle: 2
'
' To show or hide slides manually:
'   Right-click the slide thumbnail, then click Hide Slide
' To rename slides,
'   Use this VBA: ActiveWindow.View.Slide.Name = "NewSlideName"
'   Or, edit the (Name) property in the VBA Properties window.
'
   Dim sldCurrent As Slide
   Dim found As Boolean
   found = False

   LMR = Trim(UCase(LMR))
   If LMR <> "L" And LMR <> "M" Then LMR = "R"
   'Loop through each slide in presentation.
   For Each sldCurrent In ActivePresentation.Slides
        'Match shape name left, right or middle as per LMR arguement.
        'ActiveWindow.View.Slide.Name or Slide.SlideNumber
        found = False
        If LMR = "R" And LCase(right(sldCurrent.Name, Len(NameContains))) = LCase(NameContains) Then
            found = True
        ElseIf LMR = "L" And LCase(left(sldCurrent.Name, Len(NameContains))) = LCase(NameContains) Then
            found = True
        ElseIf LMR = "M" And InStr(1, LCase(NameContains), LCase(sldCurrent.Name)) Then
            found = True
        End If
        'If match found, then set shape visibility per ShowShape arguement.
        If found Then
            If ShowSlide = True Then
                ActivePresentation.Slides(sldCurrent.SlideNumber).SlideShowTransition.Hidden = msoFalse
            ElseIf ShowSlide = False Then
                ActivePresentation.Slides(sldCurrent.SlideNumber).SlideShowTransition.Hidden = msoTrue
            Else
                ActivePresentation.Slides(sldCurrent.SlideNumber).SlideShowTransition.Hidden = Not ActivePresentation.Slides(sldCurrent.SlideNumber).SlideShowTransition.Hidden
            End If
        End If
    Next       'sldCurrent
End Sub

Sub ShowHideShapes(NameContains As String _
                , Optional LMR As String = "R" _
                , Optional ShowShape As Integer = False)
' Show or Hide shapes/objects based on object name.
' Arguements:
'   NameContains (string):
'       shapes with this string will be modified.
'   LMR (string): enter L, M or R to indicate
'       searching the Left, Middle or Right of
'       the slide name, respectively.
'   ShowSlide (integer):
'       Show: True (-1)
'       Hide: False (0)
'       Toggle: 2
'
' To show, hide and/or rename objects:
'    1. Turn on Selection Pane via: Home Ribbon >
'       Select > Selection Pane.
'    2. Double-click a shape name to rename it.
'    3. Click the eye icon to the far right to show/hide a shape.

   Dim shpCurrent As Shape
   Dim sldCurrent As Slide
   Dim found As Boolean
   found = False

   LMR = Trim(UCase(LMR))
   If LMR <> "L" And LMR <> "M" Then LMR = "R"
   'Loop through each slide in presentation.
   For Each sldCurrent In ActivePresentation.Slides
      With sldCurrent
          'Loop through each shape on current slide.
          For Each shpCurrent In .Shapes
            'Match shape name left, right or middle as per LMR arguement.
            found = False
            If LMR = "R" And right(shpCurrent.Name, Len(NameContains)) = NameContains Then
                found = True
            ElseIf LMR = "L" And left(shpCurrent.Name, Len(NameContains)) = NameContains Then
                found = True
            ElseIf LMR = "M" And InStr(1, NameContains, shpCurrent.Name) Then
                found = True
            End If
            'If match found, then set shape visibility per ShowShape arguement.
            If found Then
                If ShowShape = True Then
                    shpCurrent.Visible = True
                ElseIf ShowShape = False Then
                    shpCurrent.Visible = False
                Else
                    shpCurrent.Visible = Not shpCurrent.Visible
                End If
            End If
          Next 'sldCurrent
      End With 'sldCurrent
    Next       'sldCurrent

End Sub

Sub HideNoPrint()
' Hide slides and shapes you do NOT want printed.
'
' Run this macro to hide all slides and shapes that
' end with the string "NoPrint".

' Usage.  Assume you have slides that contain animations that
' make the printed slide difficult or impossible to read.
' Let's further suppose you plan to present certain slides
' but not print them.
'   1. Add the"NoPrint" suffix to any shapes that clutter
'      the printed page.
'   2. Add the "NoPrint" suffix to slides you don't want to
'      print.
'   3. Run this macro to hide shapes and slides.
'   4. Print the slides.
'   5. Optionally, run the ShowNoPrint() macro in preparation
'      for presenting the slides.
    ShowHideShapes "NoPrint", "R", False
    ShowHideSlides "NoPrint", "R", False
End Sub

Sub ShowNoPrint()
' Unhide slides and shapes that were hidden
' to prevent them from being printed in handouts.
'
    ShowHideShapes "NoPrint", "P", True
    ShowHideSlides "NoPrint", "P", True
End Sub

Sub HideNoPressent()
' Hide objects you do NOT want to present on screen.
'
' Run this macro to hide all slides and shapes that
' end with the string "NoPresent".
'
' Usage.  Assume you have slides that contain supporting material
' that you wish to provide as printed handouts but not show.
' You can manually hide those slides and objects of course. I
' prefer to use these macros.
'   1. Add the"NoPresent" suffix to any shapes that you want
'      to print to handouts but not show on-screen.
'   2. Add the "NoPresent" suffix to slides you want to
'      print but not display on screen, such as reference slides.
'   3. Run this macro to hide the "NoPresent" shapes and slides.
'   4. Present your slides.
'   5. Optionally, run the ShowNoPresent() macro in preparation
'      for printing the slides.
'
    ShowHideShapes "NoPressent", "R", False
    ShowHideSlides "NoPressent", "R", False
End Sub

Sub ShowNoPresent()
' Unhide objects that were hidden to prevent them from
' being presented on screen.
'
    ShowHideShapes "NoPressent", "P", True
    ShowHideSlides "NoPressent", "P", True
End Sub

Sub PrepToPrintSlides()
' Unhide objects you want printed and
' hide objects you do NOT want printed.
    ShowNoPresent
    HideNoPrint
End Sub

Sub PrepToPresentSlides()
' Unhide objects you want presented and
' hide objects you do NOT want presented.
    ShowNoPrint
    HideNoPresent
End Sub

Sub DontPresentSlide()
    Dim RetVal, sldName As String
    sldName = Application.ActiveWindow.View.Slide.Name
    If InStr(1, sldName, "NoPresent", vbBinaryCompare) = 0 Then
        RetVal = RenameSlide(sldName, sldName & "-NoPresent")
    End If
    HideNoPresent
End Sub

Sub PresentSlide()
    Dim RetVal, sldName As String, strStart As String, newName As String
    'Remove the NoPresent suffix from the current slide.

    'get slide name
    sldName = Application.ActiveWindow.View.Slide.Name
    'Unhide slide
    ActivePresentation.Slides(sldName).SlideShowTransition.Hidden = msoFalse
    'remove "-NoPresent" from slide name
    Do
        strStart = InStr(1, sldName, "-NoPresent")
        If InStr(1, sldName, "-NoPresent") Then
            newName = left(sldName, strStart - 1) & right(sldName, Len(sldName) - strStart - 9)
            RetVal = RenameSlide(sldName, newName)
        End If
        sldName = Application.ActiveWindow.View.Slide.Name
    Loop Until InStr(1, sldName, "-NoPresent") = 0
    'remove "NoPresent" from slide name
    Do
        strStart = InStr(1, sldName, "NoPresent")
        If InStr(1, sldName, "NoPresent") Then
            newName = left(sldName, strStart - 1) & right(sldName, Len(sldName) - strStart - 8)
            RetVal = RenameSlide(sldName, newName)
        End If
        sldName = Application.ActiveWindow.View.Slide.Name
    Loop Until InStr(1, sldName, "NoPresent") = 0

End Sub

Sub DontPrintSlide()
    Dim RetVal, sldName As String
    sldName = Application.ActiveWindow.View.Slide.Name
    If InStr(1, sldName, "NoPrint", vbBinaryCompare) = 0 Then
        RetVal = RenameSlide(sldName, sldName & "-NoPrint")
    End If
    HideNoPrint
End Sub

Sub PrintSlide()
    Dim RetVal, sldName As String, strStart As String, newName As String
    'Remove the NoPrint suffix from the current slide.

    'get slide name
    sldName = Application.ActiveWindow.View.Slide.Name
    'Unhide slide
    ActivePresentation.Slides(sldName).SlideShowTransition.Hidden = msoFalse
    'remove "-NoPrint" from slide name
    Do
        strStart = InStr(1, sldName, "-NoPrint")
        If InStr(1, sldName, "-NoPrint") Then
            newName = left(sldName, strStart - 1) & right(sldName, Len(sldName) - strStart - 7)
            RetVal = RenameSlide(sldName, newName)
        End If
        sldName = Application.ActiveWindow.View.Slide.Name
    Loop Until InStr(1, sldName, "-NoPrint") = 0
    'remove "NoPrint" from slide name
    Do
        strStart = InStr(1, sldName, "NoPrint")
        If InStr(1, sldName, "NoPrint") Then
            newName = left(sldName, strStart - 1) & right(sldName, Len(sldName) - strStart - 6)
            RetVal = RenameSlide(sldName, newName)
        End If
        sldName = Application.ActiveWindow.View.Slide.Name
    Loop Until InStr(1, sldName, "NoPrint") = 0
End Sub

Sub HideAllCovers()
' Run this macro to hide all Covers.
    ShowHideShapes "Cover", "L", False
End Sub

Sub ShowAllCovers()
' Run this macro to hide all Covers.
    ShowHideShapes "Cover", "L", True
End Sub

Sub HideAllAnswers()
' Run this macro to hide all Covers.
    ShowHideShapes "Answer", "L", False
End Sub

Sub ShowAllAnswers()
' Run this macro to hide all Covers.
    ShowHideShapes "Answer", "L", True
End Sub

Sub HideAllQuestions()
' Run this macro to hide all Covers.
    ShowHideShapes "Question", "L", False
End Sub

Sub ShowAllQuestions()
' Run this macro to hide all Covers.
    ShowHideShapes "Question", "L", True
End Sub

Sub ShowAll()
' Run this macro to hide all shapes (Covers and Answers).
    ShowAllQuestions
    ShowAllAnswers
    ShowAllCovers
    ShowNoPrint
End Sub

Sub HideAll()
' Run this macro to hide all shapes (Covers and Answers).
    HideAllQuestions
    HideAllAnswers
    HideAllCovers
    HideNoPrint
End Sub

2
在“文件->选项->自定义功能区”中启用“开发人员”选项卡(详情:https://www.addintools.com/documents/powerpoint/where-is-developer-tab.html
在开发人员选项卡中,按照以下步骤操作并查看下面的图像(抱歉,是葡萄牙语):
  • 进入开发人员选项卡
  • 选择目标幻灯片
  • 如果幻灯片中没有活动X控件(按钮、文本框等),请从开发人员选项卡添加虚拟按钮
  • 在幻灯片上选择此按钮,然后单击开发人员选项卡上的“属性”
  • 在属性窗口顶部,有一个组合框可以选择幻灯片而不是按钮
  • 选择幻灯片并查看其编程属性,包括名称

enter image description here


很抱歉重新激活这篇旧帖。除了这种方法之外,还有其他方式可以查看幻灯片的名称吗? - NotepadPlusPlus PRO

1
我使用Sub SplitFile()函数从100多张幻灯片中创建单独的幻灯片,一切顺利!但请问有谁能告诉我我该用什么代码来自动重命名文件,假设每个幻灯片都有一个标题在文本框中?我想让幻灯片标题成为新创建的单独幻灯片的文件名。
这是我用来创建单独幻灯片(作为单独文件)的代码,感谢在线发布的人。

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

    For Each oSlide In ActiveWindow.Presentation.Slides
strTitles = strTitles _
    & "Slide: " _
    & CStr(oSlide.SlideIndex) & vbCrLf _
    & oSlide.Shapes.Title.TextFrame.TextRange.Text _
    & vbCrLf & vbCrLf

下一个oSlide 出错时转到ErrorHandler

intFileNum = FreeFile

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

正常退出: 退出子程序 错误处理: 弹出消息框,显示“遇到错误” 恢复正常退出 结束子程序


1
我不确定这是否能让您设置Slide.Name属性,因为我不是VBA程序员,但是根据我的了解,在PowerPoint 2010中命名幻灯片的最简单方法是使用大纲视图。
如果您将鼠标放在创建的幻灯片的最左边,可以向右拖动一种垂直幻灯片排序器。在该窗格的顶部,您将看到两个选项卡:幻灯片大纲
选择大纲,您将看到每个幻灯片都有编号和一个灰色的抓取按钮,可让您重新排列幻灯片。如果您在其右侧单击,可以键入任何名称,比如主页
在主视图窗格中,幻灯片将显示主页。然后,您可以将其留在那里,或通过将字体颜色更改为背景或将文本移动到演示文稿框架外来隐藏它。
顺便说一下,您可以在超链接中使用这些名称。

虽然这样做可能有一些原因,但不幸的是它实际上并没有改变幻灯片的“Name”属性。 - David Zemens

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接