gpt4 book ai didi

ms-office - Powerpoint:手动设置幻灯片名称

转载 作者:行者123 更新时间:2023-12-04 03:04:29 27 4
gpt4 key购买 nike

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

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

我的问题很像:“How to name an object within a PowerPoint slide? ”但只是在幻灯片级别。

任何帮助,将不胜感激。

最佳答案

PowerPoint 中没有允许您编辑幻灯片名称的内置功能。正如史蒂夫提到的,你必须使用 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

关于ms-office - Powerpoint:手动设置幻灯片名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16855306/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com