I have the following code to insert an updating, hyperlinked cross-reference in place of a user-typed plain text number referring to a previous list item:
Selection.InsertCrossReference referencetype:="Numbered item", _
referencekind:=wdNumberNoContext, referenceitem:=<user-entered number>,
InsertAsHyperlink:=True
I deal with documents with multiple numbered lists of different formatting, and the trouble is that if the user typed the number 5, the cross reference inserted will be to the 5th numbered item in the entire document, which may be a paragraph numbered "[0005]" instead of the user-intended list item numbered "5.", which appears much later in the document. I know it is possible to extract the list heading number as it appears for a given numbered item -- it is the ListString property of a ListFormat object; for example, Selection.Range.ListFormat.ListString
will return the number as it appears for the selected paragraph.
But does this method have an inverse that will return a numbered item given its heading number as it appears, without having to explicitly iterate through paragraphs and extract the ListString property of each paragraph that is a ListFormat object until a match is found?
Update: I have created a full solution for doing this, though the output is only in alpha stage.
https://gist.github.com/sfinktah/789cfb36b3b15025d5796433da68ffb4
Assign the last sub on the page to Shift-Alt-F9 or somesuch,type 31(a),45 or somesuch, then press Shift-Alt-F9 twice (once to select the previous text, and once to convert it into references). I may develop it properly one day as a legal helper-app.
I believe all the concepts you need are contained in this demonstration.
It both iterates all numbered paragraphs, inserting a reference to each paragraph as it goes. It will probably break if there is a paragraph with less than 2 words, or insert multiple references -- this is just a starting point.
To generate a reference to specific and [complex] numbered paragraph such as 1(a)(i), you would iterate all numbered paragraphs until you found your matching paragraph. There is a ListLevel value you can use to build a complete "1(a)(i)" string as you iterate.
Once matched, it calls the second function which creates a reference based on the ListLevelNumber and joined words that comprise the paragraph -- that required some special trial and error work, and probably isn't perfect.