We help IT Professionals succeed at work.

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

273 Views
Last Modified: 2017-11-07
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?
Comment
Watch Question

aikimarkSocial distance; Wear a mask; Don't touch your face; Wash your hands for 20 seconds
CERTIFIED EXPERT
Top Expert 2014

Commented:
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 Garroch (MVP)PowerPoint Technical Consultant
CERTIFIED EXPERT

Author

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

Social distance; Wear a mask; Don't touch your face; Wash your hands for 20 seconds
CERTIFIED EXPERT
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Jamie Garroch (MVP)PowerPoint Technical Consultant
CERTIFIED EXPERT

Author

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 :-)

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.