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

Tip: Looking for answers? Try searching our database.

how to insert DocVariable into a table cell?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kelie - 02 Oct 2007 18:38 GMT
hello,

this is how i'm doing it now. but seems awkward.

cell.Select
With ActiveDocument.ActiveWindow.Selection
   .ExtendMode = True
   .EscapeKey
End With
ActiveDocument.Fields.Add ...

can i insert the docvariable without selecting and deselecting the
cell?

thanks.
Jay Freedman - 02 Oct 2007 19:19 GMT
Not only _can_ you avoid selecting and deselecting, you _should_ avoid it
whenever possible. Instead, declare a Range variable, set it to point to the
particular cell you want, and make that Range object the value of the Range
argument in the Fields.Add statement:

   Dim myRg As Range

   ' point at the cell you want
   ' in the table you want
   Set myRg = ActiveDocument.Tables(1).Cell(2, 2).Range

   ' exclude table cell marker
   myRg.MoveEnd wdCharacter, -1

   ActiveDocument.Fields.Add _
     Range:=myRg, _
     Type:=wdFieldDocVariable, _
     Text:="dv1"

   ActiveDocument.Fields.Update

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.

> hello,
>
[quoted text clipped - 11 lines]
>
> thanks.
Kelie - 02 Oct 2007 23:42 GMT
> Not only _can_ you avoid selecting and deselecting, you _should_ avoid it
> whenever possible. Instead, declare a Range variable, set it to point to the
[quoted text clipped - 21 lines]
> Jay Freedman
> Microsoft Word MVP        FAQ:http://word.mvps.org

Thanks for your help Jay.
 
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.