none
custom Word.CaptionLabel entries are not found using ActiveDocument.GetCrossReferenceItems(ref ...) RRS feed

  • Question

  • Hello,

    I have a problem with my word VSTO add-in. I wrote the code with Visual Studio 2013 and Word 2013. Now I am using VS 15 and Office 2016. My add-in showed all references and caption labels in the word document. In Word 2016 I do not get any entries for custom caption labels, as the German "Abbildung" for figure.

    Built in Word.CaptionLabel(s) are found, also WdReferenceType Enumerators. Hence, if the BuiltIn Property is false, there are no references found, even if there are captions added (e.g. to figures). It should return a object, which I can cast to a string[], but the returned array is empty.

    To be clear: I do not mean the label itself. This is listed in Application.CaptionLabels.

    I also noticed, that my intelli sense is putting out the usage should be await ActiveDocument.GetCrossReferenceItems(ref ...), but if I put it in this way I get an exception.

    Any help would be much appreciated.

    Best regards,

    Andreas

    UPDATE:

    After trying something, it seems that this problem is concerning all CaptionLabels depending on the Office version used to create the document. If I use a document created with Word 2013 the caption labels are found, if I use a document created with Word 2016 no caption labels are passed using GetCrossReferenceItems method.

    UPDATE 2:

    After using Word 2016 a little bit more, it seems there are some bugs concerning caption labels. When I insert my caption label as above/below the whole caption text is inserted instead of the word "above" or "below". I hope some MS staff reads this and can forward the problem to the developers.

    Tuesday, March 1, 2016 6:21 PM

Answers

  • Hi Andreas,

    >>In Word 2016 I do not get any entries for custom caption labels, as the German "Abbildung" for figure.

    Do you mean you want to get Caption labels in document? Caption is not in the list of WdReferenceType, so we could not use GetCrossReferenceItems method. Caption is a separate paragraph, so I think we could loop the paragraphs and check the type.

    Here is a simple code in VBA, you could modify it to your own developing language.

    Dim p As Paragraph
    For Each p In ActiveDocument.Paragraphs
        If p.Style = "Caption" Then
        Debug.Print p.Range.Text
        End If
    Next

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, March 3, 2016 8:23 AM
  • Hello Edward,

    Thank you for your reply. Your solution is, of course, right and an alternative to get the items. I had this in an earlier version. As I run my update on each SelectionChange event I had problems with larger documents. I got a heavy processor load and, therefore, word did not run smoothly anymore (maybe that is better in Word 2016).

    My plugin is written in C# and is a VSTO COM Addin.

    My add-in reliably worked with the GetCrossReferenceItems method in documents edited with Word 2013 and 2010. Word 2016 does not seem to fill up the storage for the caption labels anymore, which is accessed by the Microsoft.Office.Interop.Word.Document.GetCrossReferenceItems(..) method.

    As you can see on this screenshot in the link below, the labels added (Figure 3-1, 4-1, etc.) are displayed in the list on the right. I added a new caption label with word 2016 and it is not added to the list.

    Screenshot link: http://www.fotos-hochladen.net/view/tempr829qe5ois.jpg

    Is this an intended behavior change for the word object model and is the only alternative to search the whole document for new labels? Because if the word dev team intends to change/fix this in coming updates I do not necessarily need to change my plugin.

    object o = activeDocument.GetCrossReferenceItems(ref referenceType); string[] arr = ((IEnumerable)o).Cast<object>() .Select(x => x.ToString()) .ToArray(); if (arr.Length < 1) Active = false;


    Thursday, March 3, 2016 1:49 PM

All replies

  • Hi Andreas,

    >>In Word 2016 I do not get any entries for custom caption labels, as the German "Abbildung" for figure.

    Do you mean you want to get Caption labels in document? Caption is not in the list of WdReferenceType, so we could not use GetCrossReferenceItems method. Caption is a separate paragraph, so I think we could loop the paragraphs and check the type.

    Here is a simple code in VBA, you could modify it to your own developing language.

    Dim p As Paragraph
    For Each p In ActiveDocument.Paragraphs
        If p.Style = "Caption" Then
        Debug.Print p.Range.Text
        End If
    Next

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, March 3, 2016 8:23 AM
  • Hello Edward,

    Thank you for your reply. Your solution is, of course, right and an alternative to get the items. I had this in an earlier version. As I run my update on each SelectionChange event I had problems with larger documents. I got a heavy processor load and, therefore, word did not run smoothly anymore (maybe that is better in Word 2016).

    My plugin is written in C# and is a VSTO COM Addin.

    My add-in reliably worked with the GetCrossReferenceItems method in documents edited with Word 2013 and 2010. Word 2016 does not seem to fill up the storage for the caption labels anymore, which is accessed by the Microsoft.Office.Interop.Word.Document.GetCrossReferenceItems(..) method.

    As you can see on this screenshot in the link below, the labels added (Figure 3-1, 4-1, etc.) are displayed in the list on the right. I added a new caption label with word 2016 and it is not added to the list.

    Screenshot link: http://www.fotos-hochladen.net/view/tempr829qe5ois.jpg

    Is this an intended behavior change for the word object model and is the only alternative to search the whole document for new labels? Because if the word dev team intends to change/fix this in coming updates I do not necessarily need to change my plugin.

    object o = activeDocument.GetCrossReferenceItems(ref referenceType); string[] arr = ((IEnumerable)o).Cast<object>() .Select(x => x.ToString()) .ToArray(); if (arr.Length < 1) Active = false;


    Thursday, March 3, 2016 1:49 PM
  • Hi Andreas,

    At present, I am afraid there is no better way. If this is a feature you want to include in the future, I suggest you submit a feedback in the link below:

    https://word.uservoice.com/

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, March 8, 2016 8:58 AM