|
-
Apr 9th, 2001, 12:02 AM
#1
Thread Starter
Lively Member
Hi
I am trying to populate a form from a word document.
ie. A document contains cust. Name, address etc. Through VB I would like to display this info on a form.
Are bookmarks the best way to go. ie. read in a character at a time until an empy space is encountered??
Not sure how though....
Any help would be appreciated....
Thanks
Kelly
-
Apr 9th, 2001, 12:13 AM
#2
Addicted Member
I would think that Bookmarks in Word would be the way to go. You can then iterate through your Bookmarks collection of the Word document returning the values.
If you named the Bookmark the same name of the corresponding Text Box, it would be pretty easy to populate. Something like the code below would work.
Code:
Dim WordApp As New Word.Application
Dim WordDoc As Word.Document
Dim WordBM As Word.Bookmark
WordApp.Visible = True
Set WordDoc = WordApp.Documents.Open(DocumentName)
For Each WordBM In WordDoc.Bookmarks
Me.Controls(WordBM.Name).Text = WordBM.Range
Next
Hope this helps,
Nathan Liebke.
-
Apr 9th, 2001, 12:39 AM
#3
Thread Starter
Lively Member
Thanks for your help, Nathan
Unless I am missing something I can`t seem to see anything in the textbox. (I have got text beside the bookmark in the word document.) The textbox stays blank.
Also will this work if I have a string of words beside the bookmark or will it only work for the 1 word.
Thanks
Kelly
-
Apr 9th, 2001, 12:52 AM
#4
Addicted Member
You highlight the field you want to be returned to VB and then Insert -> Bookmark and give it the name you want.
If you go to Tools->Options ->View tab and check the Bookmarks box you should see all the bookmarks you have created enclosed in square brackets. eg ([My Address]) Whatever is in the brackets will be returned by the Bookmark.Range property.
Hope this helps,
Nathan Liebke
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|