SlideMaster 的唯一标识符

发布于 2024-09-29 19:18:38 字数 152 浏览 0 评论 0原文

虽然我意识到幻灯片母版在给定的演示文稿中具有唯一的名称(尽管我知道这是有问题的),但有没有办法唯一地标识用户无法触摸的母版?或者,是否有与幻灯片的标签集合等效的东西,我可以在某个地方存放我自己的 ID?

对于 PowerPoint 2003 和/或 2007...提前致谢。

While I realize that a SlideMaster has a unique name in a given presentation (though I understand this to be buggy), is there a way to uniquely identify a master that a user can't touch? Alternatively, is there an equivalent to the Slide's Tags collection, somewhere I can stash my own ID?

For PowerPoint 2003 and/or 2007... Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初懵 2024-10-06 19:18:39

在 PowerPoint 2007/2010 中,您可以使用 CustomXMLParts 作为标记。这是一个演示:

Sub SetSlideMasterTag()
    Dim ap As Presentation
    Set ap = ActivePresentation
    ''#------------------------
    Dim slideMasterCustomerData As CustomerData
    Set slideMasterCustomerData = ap.SlideMaster.CustomerData
    ''#------------------------
    Dim slideMasterCustomXMLPart As CustomXMLPart
    Set slideMasterCustomXMLPart = slideMasterCustomerData.Add
    slideMasterCustomXMLPart.LoadXML ("<Tag><Item>SlideMaster</Item></Tag>")
    ''#------------------------
    Dim slideMasterTag As String
    slideMasterTag = slideMasterCustomXMLPart.Id
    ''#------------------------
    Debug.Print slideMasterTag
    Debug.Print ap.CustomXMLParts.SelectByID(slideMasterTag).XML
    ''#------------------------
    ap.CustomDocumentProperties.Add Name:="SlideMasterTag", LinkToContent:=False, _
        Type:=msoPropertyTypeString, Value:=slideMasterTag
End Sub
Sub RetrieveSlideMasterTag()
    Dim ap As Presentation
    Set ap = ActivePresentation
    ''#------------------------
    Dim slideMasterTag As String
    slideMasterTag = ap.CustomDocumentProperties.Item("SlideMasterTag").Value
    Debug.Print slideMasterTag
    ''# Is this the right slide master?
    If Not ap.SlideMaster.CustomerData(slideMasterTag) Is Nothing Then
        Debug.Print "Found you, you little bugger!"
    End If
End Sub

需要记住的几件事:

  • 您必须维护
    会话之间的slideMasterTag
    可能最好的地方是
    CustomDocumentProperties中,
    因此RetrieveSlideMasterTag
    常规。这是极不可能的
    最终用户会进入这里。

    • 如果您不想将其添加到
      CustomDocumentProperties,您会
      只需要查询全部即可
      使用 XPath 的 CustomXMLParts
      XML。
  • 上面的代码没有任何错误
    或验证检查。你需要
    查看创建代码以确保
    还没有一个名为的标签
    slideMasterTag

In PowerPoint 2007/2010 you can use CustomXMLParts as sort of a tag. Here's a demo:

Sub SetSlideMasterTag()
    Dim ap As Presentation
    Set ap = ActivePresentation
    ''#------------------------
    Dim slideMasterCustomerData As CustomerData
    Set slideMasterCustomerData = ap.SlideMaster.CustomerData
    ''#------------------------
    Dim slideMasterCustomXMLPart As CustomXMLPart
    Set slideMasterCustomXMLPart = slideMasterCustomerData.Add
    slideMasterCustomXMLPart.LoadXML ("<Tag><Item>SlideMaster</Item></Tag>")
    ''#------------------------
    Dim slideMasterTag As String
    slideMasterTag = slideMasterCustomXMLPart.Id
    ''#------------------------
    Debug.Print slideMasterTag
    Debug.Print ap.CustomXMLParts.SelectByID(slideMasterTag).XML
    ''#------------------------
    ap.CustomDocumentProperties.Add Name:="SlideMasterTag", LinkToContent:=False, _
        Type:=msoPropertyTypeString, Value:=slideMasterTag
End Sub
Sub RetrieveSlideMasterTag()
    Dim ap As Presentation
    Set ap = ActivePresentation
    ''#------------------------
    Dim slideMasterTag As String
    slideMasterTag = ap.CustomDocumentProperties.Item("SlideMasterTag").Value
    Debug.Print slideMasterTag
    ''# Is this the right slide master?
    If Not ap.SlideMaster.CustomerData(slideMasterTag) Is Nothing Then
        Debug.Print "Found you, you little bugger!"
    End If
End Sub

A couple of things to remember:

  • You have to maintain the
    slideMasterTag between sessions.
    Probably the best place to do this is
    in the CustomDocumentProperties,
    hence the RetrieveSlideMasterTag
    routine. It is highly unlikely that
    an end user would go into here.

    • If you didn't want to do add this to
      CustomDocumentProperties, you would
      just need to query all
      CustomXMLParts using XPath for your
      XML.
  • The code above doesn't do any error
    or validation checking. You'll need
    to see create code to ensure that
    there is not already a tag called
    slideMasterTag.
花海 2024-10-06 19:18:39

我最初认为没有好方法来保护 SlideMaster 名称不被用户使用,因为它似乎很容易通过 Master 视图提供。在 2007 年,这很容易实现,如上所示:功能区的“查看”选项卡、“幻灯片母版”按钮、右键单击任何母版并重命名。与 2003 年几乎相同,查看菜单 >大师>幻灯片母版,右键单击左侧缩略图列表中的相关母版,然后重命名。

令人高兴的事实是,这并没有重命名master,而是重命名设计。当涉及到这两个对象时,Ppt 对象模型并不是很简单;每个母版显然都是设计的父级,但出于所有意图和目的,它们都是一对一使用的,并且每个母版都将另一个公开为属性:SlideMaster.Design(对于“活动“仅限幻灯片母版)或 Design.SlideMaster (至少就幻灯片母版而言 - 我不与其他三个一起工作,所以不能在这里真正与他们交谈)。当用户执行上述一系列步骤时,等效的 vba 是 myDesign.Name = "SomeNewName",而不是 mySlideMaster.Name = "SomeNewName"。主人的名字不受影响;同样,如果在 VBA 中执行 mySlideMaster.Name = "SomeNewVBAName",用户可能选择的相应设计名称将保持不变。

I initially thought there was no good way to protect a SlideMaster name from a user, because it seems to be very easily provided via the Master view. In 2007, this is very easy to get to, as indicated above: View tab of ribbon, Slide Master button, right-click any master, and rename. Pretty much the same in 2003, View menu > Master > Slide Master, right-click the master in question in the lefthand thumbnail list, rename.

The happy fact is that this does not rename the master but rather the design. The Ppt object model is not very straightforward when it comes to these two objects; each master is apparently the parent of a design, but for all intents and purposes, they are employed 1-to-1, and each exposes the other as a property: SlideMaster.Design (for the "active" slide master only) or Design.SlideMaster (at least as far as the slide master is concerned--I'm not working with the other three, so can't really speak to them here). When the user follows the series of steps detailed above, the equivalent vba is myDesign.Name = "SomeNewName", not mySlideMaster.Name = "SomeNewName". The master's name is unaffected; likewise, if in VBA I execute mySlideMaster.Name = "SomeNewVBAName", the corresponding Design name a user might have chosen remains intact.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文