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?
LVL 15
Jamie GarrochSenior Technical Consultant at BrightCarbonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aikimarkCommented:
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.
Jamie GarrochSenior Technical Consultant at BrightCarbonAuthor Commented:
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

aikimarkCommented:
I had to iterate the oCopy variable to get the GUID created during the copy/paste operation
Sub TestCustomXML()
  Dim GUID As String
  Dim oCopy As Shape
  Dim oCustData As Object
  Dim LatestAddedGUID As String
  
  ' Write some XML to the selected shape
  With ActiveWindow.Selection.ShapeRange(1)
    With .CustomerData
      With .Add
        GUID = .Id
        Debug.Print GUID, "Original 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)
  For Each oCustData In oCopy.CustomerData
    LatestAddedGUID = oCustData.Id
  Next
  Debug.Print LatestAddedGUID, "Added GUID"
  
  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
    Debug.Print .Item(LatestAddedGUID).XML
  End With
End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jamie GarrochSenior Technical Consultant at BrightCarbonAuthor Commented:
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 :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.