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 / March 2007

Tip: Looking for answers? Try searching our database.

Inserting field from a VB macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Flint - 22 Mar 2007 12:46 GMT
What is the clean way to insert a field from a macro?
I tried to record it, but the result was:
   Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
       "AUTHOR  ", PreserveFormatting:=True
Thanks.
Jonathan West - 22 Mar 2007 14:36 GMT
> What is the clean way to insert a field from a macro?
> I tried to record it, but the result was:
>    Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:=
> _
>        "AUTHOR  ", PreserveFormatting:=True
> Thanks.

What is the problem with that code as far as you are concerned? What is
"unclean" about it?

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

Klaus Linke - 25 Mar 2007 13:58 GMT
>> What is the clean way to insert a field from a macro?
>> I tried to record it, but the result was:
>>    Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
>> Text:= _
>>        "AUTHOR  ", PreserveFormatting:=True

> What is the problem with that code as far as you are concerned? What is
> "unclean" about it?

I guess Flint's point is that this would be cleaner:

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

The macro recorder isn't perfect... Who knew? <g>

Klaus
 
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.