Need help filling in a word document from VB

Kebie
11-26-2003, 09:37 PM
I think this question gets asked a lot so if you know of a thread where it explains what I can do then please feel free to send me a link. I searched a bunch in the forum, but couldn't really find the solution I was looking for.

Basically I am doing a project for a client who has given a bunch of documents with no word macros in them yet or anything. They are sick of filling in certail fields every time so they had us develop a VB program where they fill in an assortment of text boxes then save that data to a database. They can then go to a screen and click on a button pertaining to the word document they would like to generate this button opens up word with all of the data magicaly appearing filled in.

I get the idea of where I think I could use word macros (never done any office integration programming) and get access to data from the Access database that everything is saved in, but I need a way to send word the primary key so it knows which record to get all that data from.

If anyone could help me or suggest anything that would be great. I think I saw a thread that just suggested opening the .doc file and text replacing fields by putting in a dummy value and searching for it, but I thought their may be an easier and or better way.

Kebie
11-27-2003, 07:31 PM
I still need help with the original problem but I have another one. I will have templates I guess of each doc file that I don't want over ridden when the user saves.. is there any way to set a value in a word document so when it is saved they have to use save as?

Basically I don't want them overiding the templates.

Kebie
11-29-2003, 12:22 AM
Ok so I figured out the word replace and sort of the save, what I do is copy all the data from the template to a new document then I replace the words so they have to save.. However I get an uneeded error where it opens up 2 word documents, 1 the unsaved replaced word, and the 2nd is the original template with no words replaced (I dont want this opened)

Here is my code, if any one could help that would be great!


Dim wdApp As Word.Application
Dim wdDoc As Word.Document

Set wdApp = New Word.Application
Set wdDoc = wdApp.Documents.Add() 'Create a new document to not save over the old
wdDoc.Content = wdApp.Documents.Open(FileName:="F:\testVB\Document_Templates\test2.doc").Content

With wdDoc.Content.Find
.Text = "%%wordReplace%%"
.MatchWholeWord = True
.ClearFormatting
.Replacement.Text = Text1.Text
.Replacement.ClearFormatting
'Start finding and replacing
.Execute Replace:=wdReplaceAll = 2, Forward:=True
End With
wdApp.Visible = True

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum