Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Microsoft Word variables 2

Status
Not open for further replies.

rdavis

Programmer
Apr 29, 2002
157
US
What is the best way to input data from a VB application to Microsoft Word? I've started out using the Replace function (to look for a string in the document e.g. <NAME> and replace with data>), then I looked into fields (DocVariable), but it looks like you can only reference a field by an index, not by its name. Then I saw bookmarks. I want to use the best way. Any input would be appeciated.

Thanks
Rob
 
Depends on what you need to do.
Bookmarks are uniquely named therefore there will only be one instance per document.
Whereas if you need to find several specific strings then you may need to use Find/Replace.

I've found use for both of the above.

pmrankine
 
But you can have more than one bookmark, right? I'm just trying to find the 'right' way, if there is any. Like I said, I found three ways to do what I am trying to do.

Thank
Rob
 
Yes you can have more than one bookmark, I don't know if there is a limit to the number (I've used about 20 previously).
As for the 'best way'..
as I said it depends on what you want to do:
If it's - go to a specific place in the document e.g. &quot;two lines below the address&quot; then use a bookmark.
If it's - go to a specific word/phrase that may not be in the same place then use Find but be aware that there may be other instances of the word/phrase that you are looking for.

Also when amending Word documents make sure you have control over the documents or else your bookmarks and/or phrases to look for may not be in the document after a user gets their hands on it.

pmrankine
 
I do have control over the documents. This is why I am automating Word. I actually have passwords for the documents, then open them up from VB. Actually all of the phrases/bookmarks are going to be assigned by me. It is actually assigning 'variables' to the word document, then me changing the value. and all of the docs are going to be static. (Once I create the template, it is never going to change). I probably leaning more towards bookmarks.

Thanks
Rob
 
If it's a 'boiler-plate' operation (sounds like it is) then I would use Bookmarks. They're easy to produce and easy to use in code.
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
That's the phrase I was looking for, boiler plate. That's exactly what I am doing. I just started looking into bookmarks, and that is what I am finding out. Bookmarks look a lot easier than fields. I'll just have to change all my boiler plate' documents now. Thanks all

Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top