Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2007

Tip: Looking for answers? Try searching our database.

Can Word VBA Insert Nested Fields?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paul J - 20 Jul 2007 08:56 GMT
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 - 20 Jul 2007 09:32 GMT
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

> It is common practice to Insert, Fields into a document and then
> Insert,Fields within them (nested).
[quoted text clipped - 22 lines]
>
> Paul J

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Jay Freedman - 20 Jul 2007 14:26 GMT
Another example of similar code is at
http://www.word.mvps.org/FAQs/MacrosVBA/NestedFieldsWithVBA.htm.

Signature

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.

> Paul,
> Here is a code snippet where I was creating a nested field to divide
[quoted text clipped - 40 lines]
>>
>> Paul J
Paul J - 20 Jul 2007 14:34 GMT
Russ & Jay

Your help is much appreciated.

Paul J

> Another example of similar code is at
> http://www.word.mvps.org/FAQs/MacrosVBA/NestedFieldsWithVBA.htm.
[quoted text clipped - 43 lines]
> >>
> >> Paul J
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.