Powerpoint:手动设置幻灯片名称 [英] Powerpoint: Manually set Slide Name

查看:405
本文介绍了Powerpoint:手动设置幻灯片名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Context: A PowerPoint slide in C# has a property Slide.Name (usually contains an arbitrary string value). In my C# application I would like to use this property to identify slides (the slide order is to unreliable).

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

Question: How can I manually set the Slide.Name property in the PowerPoint Application?

我的问题非常类似于:"如何在PowerPoint幻灯片中命名对象?",但仅在幻灯片级别上命名.

My problem is very like to the: "How to name an object within a PowerPoint slide?" but just on the slide level.

任何帮助将不胜感激.

推荐答案

PowerPoint中没有内置功能可让您编辑幻灯片的名称.正如Steve所提到的,您必须使用VBA代码来完成.幻灯片 name 不会因插入更多幻灯片而改变,即使关闭PowerPoint,它也将保持不变.在VBA代码中设置的幻灯片名称是永久性的.这是我编写的一些代码,可让您轻松查看当前所选幻灯片的名称并允许对其重命名:

There is no built-in functionality in PowerPoint that allows you to edit the name of a slide. As Steve mentioned, you have to do it using VBA code. The slide name will never change due to inserting more slides, and it will stay the same even if you close PowerPoint; the slide name set in VBA code is persistent. Here's some code I wrote to allow you to easily view the name of the currently selected slide and allow you to rename it:

'------------------------------------------------------------------
' 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

这篇关于Powerpoint:手动设置幻灯片名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆