Results 1 to 4 of 4

Thread: Word Doc to VB Form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Posts
    86

    Wink

    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

  2. #2
    Addicted Member GungaDin's Avatar
    Join Date
    Apr 2001
    Location
    Brisbane, Australia
    Posts
    146
    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.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Posts
    86
    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

  4. #4
    Addicted Member GungaDin's Avatar
    Join Date
    Apr 2001
    Location
    Brisbane, Australia
    Posts
    146
    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
  •  



Click Here to Expand Forum to Full Width