user2579544
user2579544

Reputation: 31

Create a custom office document property that is linked to content inside the document

I want to create a custom document property in powerpoint that is linked to the document content in C#.

I found various examples, but they all create custom document properties WITHOUT linking to document content.

What I want to achieve is that a user selects text in any shape and by clicking a button, the custom document property is created together with a link to the source. I want to be able to retrieve it later and on demand jump to the linked content.

Here is the code snippet that I'm using:

Microsoft.Office.Core.DocumentProperties properties;
properties = (Office.DocumentProperties)this.myOCMModule.PowerPointApp.ActivePresentation.CustomDocumentProperties;
Microsoft.Office.Interop.PowerPoint.Selection powerPointSelection  = this.myMainOCMModule.PowerPointApp.ActiveWindow.Selection;
PowerPoint.TextRange textRange = powerPointSelection.TextRange;
properties.Add("Test1", true, Microsoft.Office.Core.MsoDocProperties.msoPropertyTypeString, textRange.Text, textRange);

The custom property is created but the link is not valid. When I open the custom properties in PowerPoint, it the custom property appears with a broken link.

When iIdo it manually by creating a custom property it works when doing it like described here. I want to do the same thing programmatically.

In the MS reference it states

The source of the specified link is defined by the container application.

Maybe it can't resolve the textRange variable properly?

Does anyone know how i can make this work?

Upvotes: 0

Views: 870

Answers (1)

Steve Rindsberg
Steve Rindsberg

Reputation: 14810

See comment above, but I think there may be a more reliable/controllable way of doing what you want.

When the user creates one of your "bookmarks", your code can add a tag to the shape in question. In VBA, this is as simple as:

oSh.Tags.Add "TagName", "Value of my tag"
' assuming oSh contains a reference to the shape you want to mark

You'd use the same tag name each time but change the tag value for each shape.

To jump to the tagged content, something like this (insert obligatory aircode warning here):

Sub JumpToTaggedContent(sTagValue as String)
Dim oSl as Slide
Dim oSh as Shape
  For Each oSl in ActivePresentation.Slides
    For Each oSh in oSl.Shapes
       If oSh.Tags("TagName") = sTagValue Then  ' you've found it
          ActiveWindow.View.GoToSlide(oSh.Parent.SlideIndex)
          oSh.Select
          Exit Sub
       End If
    Next
  Next
End Sub

Upvotes: 0

Related Questions