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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass a variable to MS Word as a bookmark?

Status
Not open for further replies.

megkhp

Programmer
Mar 10, 2003
14
0
0
US
I created a several bookmarks in a word document, and I wish to pass some variables from a VFP form to the bookmarks, please help.
 
yan123

I'm not sure what you are trying to do, since in Word you cannot pass a parameter either, but here is how to get to a bookmark. You may want to explain what you are trying to pass.

Code:
o=CREATEOBJECT("word.application")
o.Documents.Open("c:\mydoc.doc")
myDocument=o.Selection
myDocument.GoTo.Bookmarks("Bookmark1")
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Thank you, Mike. In fact, what I did was created some form fields in a word document, these form fields are also the bookmarks. Then I built a VFP form to capture users' input and I try to pass the data to those form fields.

Anyway, I've worked out the solution:

oWord = CreateObject("Word.Application")
oWord.DisplayAlerts = .F.
** open the word document containing the form fields.
oWordDoc = oWord.Documents.Open("C:\temp\test\test.doc")
** to get the form field's name: right click on a form
** field in your word document --> Field Setting
** --> Bookmark
oWordDoc.FormFields("form_field_name").Result = thisform.text1.value
oWordDoc.PrintOut()
oWord.Quit()
RELEASE oWord


 
yan123

Glad you found your solution, although it has nothing to do with bookmarks, but rather fields. Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top