vba 如何命名 PowerPoint 幻灯片中的对象?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3074209/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 10:34:04  来源:igfitidea点击:

How to name an object within a PowerPoint slide?

vbapowerpointpowerpoint-vba

提问by Justin

So I know how to name a textbox, or a like object in PowerPoint with VB, but I was wondering if there was a way to name objects through the Ribbon (PowerPoint 2007). For instance, if I add a text box onto a slide, is there a way to assign it a name (sort of like the properties window in access, or the textbox in Excel 2003 at the top left side where you can enter the name)?

所以我知道如何使用 VB 在 PowerPoint 中命名文本框或类似对象,但我想知道是否有办法通过功能区(PowerPoint 2007)命名对象。例如,如果我在幻灯片上添加一个文本框,有没有办法为其指定一个名称(有点像访问中的属性窗口,或 Excel 2003 中左上角的文本框,您可以在其中输入名称) ?

Basically so I can reference it in code later; without having to use code to name each and every object i add after the fact. Perhaps an easier way through the Ribbon?

基本上,我可以稍后在代码中引用它;无需使用代码来命名我事后添加的每个对象。也许通过功能区更简单的方法?

回答by Todd Main

Yes. Click on the object (textbox, shape, etc.) to select the object and in the Drawing Tools | Formattab, click on Selection Panein the Arrangegroup. From there, you'll see names of objects - you can double click (or press F2) on any name and rename it. By deselecting it, it becomes renamed. You can also get to this from the Hometab -> Drawinggroup -> Arrangedrop-down -> Selectionpane or by pressing ALT + F10.

是的。单击对象(文本框、形状等)以选择对象并在绘图工具 | 格式选项卡,单击排列组中的选择窗格。从那里,您将看到对象的名称 - 您可以双击(或按)任何名称并重命名它。通过取消选择它,它会被重命名。您也可以从主页选项卡 ->绘图组 ->排列下拉菜单 ->选择窗格或按。F2ALT + F10

回答by Bhanu Sinha

Select the Object -> Format -> Selection Pane -> Double click to change the name

选择对象 -> 格式 -> 选择窗格 -> 双击更改名称

enter image description here

在此处输入图片说明

回答by Dudi

While the answer above is correct I would not recommend you to change the name in order to rely on it in the code.

虽然上面的答案是正确的,但我不建议您更改名称以在代码中依赖它。

Names are tricky. They can change. You should use the ShapeId and SlideId.

名字很棘手。他们可以改变。您应该使用 ShapeId 和 SlideId。

Especially beware to change the name of a shape programmatically since PowerPoint relies on the name and it might hinder its regular operation.

尤其要注意以编程方式更改形状的名称,因为 PowerPoint 依赖于名称并且可能会妨碍其正常操作。

回答by Hauns TM

THIS IS NOT AN ANSWER TO THE ORIGINAL QUESTION, IT'S AN ANSWER TO @Teddy's QUESTION IN @Dudi's ANSWER'S COMMENTS

这不是对原始问题的回答,而是对@Dudi 回答评论中@Teddy 问题的回答

Here's a way to list id's in the active presentation to the immediate window (Ctrl + G) in VBA editor:

这是一种将活动演示文稿中的 id 列出到 VBA 编辑器中的即时窗口 (Ctrl + G) 的方法:

Sub ListAllShapes()

    Dim curSlide As Slide
    Dim curShape As Shape

    For Each curSlide In ActivePresentation.Slides
        Debug.Print curSlide.SlideID
        For Each curShape In curSlide.Shapes

                If curShape.TextFrame.HasText Then
                    Debug.Print curShape.Id
                End If

        Next curShape
    Next curSlide
End Sub

回答by Sha

Click Insert ->Object->Create from file ->Browse.

单击插入 -> 对象 -> 从文件创建 -> 浏览。

Once the file is selected choose the "Change icon" option and you will be able to rename the file and change the icon if you wish.

选择文件后,选择“更改图标”选项,您可以根据需要重命名文件和更改图标。

Hope this helps!

希望这可以帮助!