Avatar of Jamie Garroch (MVP)
Jamie Garroch (MVP)Flag for United Kingdom of Great Britain and Northern Ireland asked on

Returning the GUID of an unknown CustomXMLPart in PowerPoint's CustomerData object

I'm experimenting with saving custom XML data to [shape] objects in PowerPoint using the object's CustomerData collection object which stores one or more CustomXML parts. There are three main methods and one property for the CustomerData object:

.Add (method)
.Item (method)
.Delete (method)
.Count (property)

Unlike other collections in the OM, items in the collection are read using a GUID string rather than a numerical index. for example:

Sub TestReadXML()
  Dim GUID As String
  GUID = "{CBAC284D-9000-4CFE-8E8F-FAD5CC8BCAA7}"
  With ActiveWindow.Selection.ShapeRange(1).CustomerData
    With .Item(GUID)
      Debug.Print .XML
    End With
  End With
End Sub

Open in new window


The GUID is created automatically by the .Add method when the CusomXMLPart is initially created so at that point it can be read and saved:

Sub TestWriteXML()
  Dim GUID As String
  With ActiveWindow.Selection.ShapeRange(1).CustomerData
    With .Add
      GUID = .Id
      .LoadXML "<testXML/>"
    End With
  End With
End Sub

Open in new window


Now, given the fact that the GUID cannot be present in more than one CustomXMLPart, either for the same object or multiple objects, when an object that contains a CustomXMLPart is copied, the original maintains its GUID but the copy is assigned a new one automatically.

Let's say I have a shape selected in the example above and I add the XML part, then copy/paste the shape, the new shape has been assigned the same XML data but with a different GUID.

How can I find out what that new GUID is?!

Is it deliberately inaccessible for security reasons or is this just an incomplete part of the PowerPoint OM?
XMLVBAMicrosoft PowerPoint* Object Oriented Programming

Avatar of undefined
Last Comment
Jamie Garroch (MVP)

8/22/2022 - Mon
aikimark

I don't know why MS made this decision.  We just have to live with it.

When you create a new shape, you should be able to assign the new shape to a variable and inspect its properties.  Then, place that shape in your presentation.  It is now a two-step process, but you should be able to glean the GUID.
ASKER
Jamie Garroch (MVP)

Thanks aikimark. So, how could I modify the following code example to return the new GUID?

Option Explicit

Sub TestCustomXML()
  Dim GUID As String
  Dim oCopy As Shape
  
  ' Write some XML to the selected shape
  With ActiveWindow.Selection.ShapeRange(1)
    With .CustomerData
      With .Add
        GUID = .Id
        Debug.Print GUID
        .LoadXML "<testXML/>"
      End With
    End With
    ' Copy the selected shape
    .Copy
  End With
  
  ' Paste a copy of the selected shape to the same slide
  ' Note : This forces the CustomXMLPart GUID to change
  Set oCopy = ActiveWindow.View.Slide.Shapes.Paste(1)
  
  With oCopy.CustomerData
    ' How can I return the new GUID from this pasted copy of the original shape?
    ' The next line will error becuase the GUID set above has changed
    Debug.Print .Item(GUID).XML
  End With
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
aikimark

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Jamie Garroch (MVP)

Ahhhh. The critical line in all of this is:

[code]Dim oCustData As Object[/code]

In another test, I had:

[code]Dim oCustData As CustomerData[/code]

And that would raise a "Method or data member not found".

So the GUID is in fact in the OM but the property is not? I don't understand what's going on here! Anyway, I got the answer so thank you :-)
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23