I'm creating a Word VBA macro to insert a text frame containing an image and its caption, and then create a cross reference to it in the main document text.
But Word doesn't find the caption if it's in a text frame.
Here's illustrative code:
Sub ShowMe()
Dim items() As String
items = ActiveDocument.GetCrossReferenceItems("Figure")
MsgBox ("Found " & UBound(items))
End Sub
If the caption is of a thing (say, a picture, table, or just a para) that's inline in the main document text it finds it. But if the caption is in a text frame or a text box, whether it's a caption para that I create within the text frame, or if I simply click the text frame and do 'Insert caption' (which actually creates a text box below the frame), I get zero.
I've tried creating the cross reference just by building the REF field manually, but it doesn't work reliably. I suspect there's some magic about the cross reference process creating a new hidden bookmark when required.
Any suggestions, please?