Results 1 to 3 of 3

Thread: Wordaccess in VB

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2000
    Posts
    1
    Is there any way I can alter text in a Word document from VB? I want to be able to change a document from, say:

    Name :
    Occupation :

    to

    Name: Joe Smith
    Occupation: Farmer

    or something like that. Is this possible?

  2. #2
    Lively Member
    Join Date
    Dec 1999
    Posts
    106
    I did something similar to this ages ago, I had a document template which I populated with data from VB. I placed a bookmark at each point in the document template I wanted data, then created a word object in VB, moved to each bookmark and inserted the text I wanted, here is a quick example I did up using Word 97 and VB 6, hope it helps..

    Dim appWrd As Word.Application
    Dim docWrd As Word.Document
    Dim rngWrd As Word.Range

    Set appWrd = New Word.Application
    appWrd.Visible = True
    Set docWrd = appWrd.Documents.Open("d:\tmp\test.dot")

    docWrd.Bookmarks("Name").Select
    Set rngWrd = docWrd.Range(docWrd.Bookmarks("Name").Start, docWrd.Bookmarks("Name").End)
    rngWrd.InsertBefore "Name here"

    Set rngWrd = docWrd.Range(docWrd.Bookmarks("Address").Start, docWrd.Bookmarks("Address").End)
    docWrd.Range.InsertBefore "Address here"

  3. #3
    Lively Member
    Join Date
    Dec 1999
    Posts
    106
    Sorry, forgot to say you need to set a reference to Microsoft Word 8.0 Object Library in your project ....

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