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

Tip: Looking for answers? Try searching our database.

Inserting and later updating a value in word

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
morau99@hotmail.com - 11 Jun 2007 16:39 GMT
I'd like to have a user press a button and call some code that will
insert a number into a word document after getting the number from a
dialog.  The user will insert as many as they need throughout the
document.  Then, I'd like the number value of each inserted number to
be incremented when the user presses a second button.  (basically I
need integer values that a user can insert into the proper locations
in the doc that the user can later simply mass update by pressing a
button).

I'm familiar with VBA but not really so much with Word so I'm not sure
how one usually goes about this.  I've used bookmarks to insert values
before, but not later update them.  A field also seems like it might
be appropriate, but they don't work quite how I imagined.  I searched
around the forums but didn't find anything that helped me out with
this.  Any pointers in the right direction would be much appreciated.

Thank you.
morau99@hotmail.com - 11 Jun 2007 21:45 GMT
On Jun 11, 8:39 am, mora...@hotmail.com wrote:
> I'd like to have a user press a button and call some code that will
> insert a number into a word document after getting the number from a
[quoted text clipped - 13 lines]
>
> Thank you.

Here's the code I came up with to add a field and a corresponding
CustomDocumentProperty with a particular value:

   ActiveDocument.CustomDocumentProperties.Add Name:=strName
LinkToContent:=False, Value:=strText, Type:=msoPropertyTypeString
   ActiveDocument.Fields.Add Range:=Selection.Range,
Type:=wdFieldDocProperty, Text:=strName
   ActiveDocument.Fields.Update

To update the value, I just update the property's value in some other
code.  I also added some code to make sure if a user deletes a field
the corresponding custom property also gets deleted.

Hope this helps someone else out.
Edward Thrashcort - 11 Jun 2007 21:57 GMT
Use the macro recorder while you do the job manually.  Then look at the code
(Alt-F11) and see the online help to explain the functions used

You will need to manage the ActiveDocument.Bookmarks collection

Beware that bookmarks are easily destroyed by users "meddling" with the
document!

Eddie
> *From:* morau99@hotmail.com
> *Date:* Mon, 11 Jun 2007 08:39:27 -0700
[quoted text clipped - 16 lines]
>
> Thank you.
 
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.