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?
Printable View
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?
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"
Sorry, forgot to say you need to set a reference to Microsoft Word 8.0 Object Library in your project ....