|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
How to insert a cross reference nested in a TC field and automatically get the correct autonumber?
Hi,
I'm trying to insert a TC field and include a cross reference to the current paragraph inside of it (nested). I can easily do this if adding it manually by inserting the fields but am struggling to do it via VBA. This is the rough code I have so far: Code:
Dim currentParagraph as Paragraph Set currentParagraph = Selection.Paragraphs(1) currentParagraph.Range.End = currentParagraph.Range.End - 1 Dim level as Long level = 1 Dim crossRefText as String crossRefText = "{REF }" & vbTab & Trim(currentParagraph.Range.Text) & " \l " & level Dim currentNumber as String currentNumber = currentParagraph.Range.ListFormat.ListString Dim oRng as Range Set oRng = currentParagraph.Range With oRng .Fields.Add Range:=oRng, Type:=wdFieldTOCEntry, Text:=crossRefText, PreserveFormatting:=False .Collapse 1 .MoveEndUntil "}" .End = .End + 1 .MoveStartUntil "{" .Text = "" .InsertCrossReference wdRefTypeNumberedItem, wdNumberFullContext, currentNumber, True, False, True, "." .Fields.Update End With
I have attached a couple of screenshots showing what i'd like to see, with and without field codes on. The document is attached, too and is a good representation of a small example of one of the multilevel lists being used. You may ask: Why am I using TC fields rather than styles? I am using styles for some of the TOC, but I resorted to TC fields because I couldn't get Word to behave itself with the requirements of our business. It is working, but would work significantly better with cross references. There were a number of issues with restarting numbering, incorrect formatting, etc. I've posted about this before but I don't think it's too relevant at the moment. Hopefully this makes sense! Thanks |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How do I create a cross reference to a changeable Sequence field that can automatically update | KRoger | Word | 1 | 08-27-2018 03:08 PM |
Insert a cross-reference in a caption | RomFigo | Word | 9 | 09-25-2015 12:32 AM |
cross-reference to field | eNGiNe | Word | 1 | 02-27-2015 07:46 PM |
Help with set up of automatically updating cross reference. | lukebrown | Word VBA | 5 | 09-11-2013 09:38 AM |
Cross-reference together with Mathtype formula is not working correct | Santa_Clause | Word | 2 | 02-02-2010 04:37 AM |