Discussion:
Can Word VBA Insert Nested Fields?
(too old to reply)
Paul J
2007-07-20 07:56:01 UTC
Permalink
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
Russ
2007-07-20 08:32:23 UTC
Permalink
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
Post by Paul J
It is common practice to Insert, Fields into a document and then
Insert,Fields within them (nested).
{ 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.
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
--
Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID
Jay Freedman
2007-07-20 13:26:15 UTC
Permalink
Another example of similar code is at
http://www.word.mvps.org/FAQs/MacrosVBA/NestedFieldsWithVBA.htm.
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
Post by Russ
Paul,
Here is a code snippet where I was creating a nested field to divide
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
Post by Paul J
It is common practice to Insert, Fields into a document and then
Insert,Fields within them (nested).
{ 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.
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
Paul J
2007-07-20 13:34:31 UTC
Permalink
Russ & Jay

Your help is much appreciated.

Paul J
Post by Jay Freedman
Another example of similar code is at
http://www.word.mvps.org/FAQs/MacrosVBA/NestedFieldsWithVBA.htm.
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
Post by Russ
Paul,
Here is a code snippet where I was creating a nested field to divide
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
Post by Paul J
It is common practice to Insert, Fields into a document and then
Insert,Fields within them (nested).
{ 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.
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
Continue reading on narkive:
Search results for 'Can Word VBA Insert Nested Fields?' (Questions and Answers)
5
replies
I have one problem based on Excel spreadsheet drop down menu?
started 2008-05-29 10:43:30 UTC
software
Loading...