Powerpoint:手动设置幻灯片名称

Cer*_*nic 10 powerpoint ms-office

上下文: C#中的PowerPoint幻灯片具有属性Slide.Name(通常包含任意字符串值).在我的C#应用​​程序中,我想使用此属性来识别幻灯片(幻灯片顺序是不可靠的).

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

我的问题非常像:" 如何在PowerPoint幻灯片中命名对象?"但只是在幻灯片上.

任何帮助,将不胜感激.

Mat*_*aus 11

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
Run Code Online (Sandbox Code Playgroud)


Ste*_*erg 5

你不能手动设置幻灯片名称,但是通过一些代码,它很简单。在 VBA 中,例如:

Sub NameThatSlide()
  ActivePresentation.Slides(1).Name = "Whatever You Like Here"
End Sub
Run Code Online (Sandbox Code Playgroud)