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 / February 2005

Tip: Looking for answers? Try searching our database.

creating nested fields

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Luc Benninger - 28 Feb 2005 12:50 GMT
I fail to create nested fields. I would like my vba code to insert
following formula into a table cell:

{={ NUMPAGES \* MERGEFORMAT }+3}

any hints greatly appreciated!
Luc
Dave Lett - 28 Feb 2005 14:31 GMT
Hi Luc,

There are many ways you could do this, and this is only one:

Selection.Fields.Add _
   Range:=Selection.Range, _
   Type:=wdFieldNumPages, _
   Text:="", _
   PreserveFormatting:=True

Set oRng = Selection.Paragraphs(1).Range
With oRng
   .MoveEnd unit:=wdCharacter, Count:=-1
   .InsertBefore Text:="="
   .InsertAfter Text:="+3"
   .Select
End With
With Selection.Fields
   .Add _
       Range:=Selection.Range, _
       Type:=wdFieldEmpty, _
       PreserveFormatting:=False
   .Update
End With

HTH,
Dave

> I fail to create nested fields. I would like my vba code to insert
> following formula into a table cell:
[quoted text clipped - 3 lines]
> any hints greatly appreciated!
> Luc
Luc Benninger - 28 Feb 2005 14:43 GMT
Dave, thanks a lot!

> Hi Luc,
>
[quoted text clipped - 31 lines]
>>any hints greatly appreciated!
>>Luc
Jay Freedman - 28 Feb 2005 15:10 GMT
Hi Luc,

There's more on this topic at
http://word.mvps.org/FAQs/MacrosVBA/NestedFieldsWithVBA.htm, including how
to work with nested fields in headers and footers (which is where I suspect
your field is going).

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> Dave, thanks a lot!
>
[quoted text clipped - 33 lines]
>>> any hints greatly appreciated!
>>> Luc
Charles Kenyon - 28 Feb 2005 20:05 GMT
Another alternative is to create your field manually, save it as an AutoText
entry, and use code to insert the AutoText.
Signature


Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

>I fail to create nested fields. I would like my vba code to insert
>following formula into a table cell:
[quoted text clipped - 3 lines]
> any hints greatly appreciated!
> Luc

Rate this thread:






 
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.