Can Word VBA Insert Nested Fields?

P

Paul J

It is common practice to Insert, Fields into a document and then
Insert,Fields within them (nested).

For example:

{ MACROBUTTON TestMacro { SYMBOL 254 \a \f Wingdings \s 12 \* MERGEFORMAT
}}

I know that Word VBA can also be used to add a field to a document.

For example:

Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
Text:="MACROBUTTON TestMacro X ", _
PreserveFormatting:=False

or

Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
Text:="SYMBOL 254 \a \f Wingdings \s 12 ", PreserveFormatting:=True

BUT is it possible for Word VBA to add "nested" fields to a document?

As usual, any help would be greatly appreciated.

Paul J
 
R

Russ

Paul,
Here is a code snippet where I was creating a nested field to divide the
number of words in a document by 2:

Selection.fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"INFO NumWords", PreserveFormatting:=False
Selection.PreviousField
Selection.fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.TypeText Text:="="
Selection.NextField
Selection.Collapse direction:=wdCollapseEnd
Selection.TypeText Text:="/2"
Selection.Collapse direction:=wdCollapseEnd
'Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.PreviousField.Update
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top