 |
 |

11-26-2003, 09:37 PM
|
|
Newcomer
|
|
Join Date: Nov 2003
Posts: 3
|
|
Need help filling in a word document from VB
|
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.
|
|

11-27-2003, 07:31 PM
|
|
Newcomer
|
|
Join Date: Nov 2003
Posts: 3
|
|
|
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.
|
|

11-29-2003, 12:22 AM
|
|
Newcomer
|
|
Join Date: Nov 2003
Posts: 3
|
|
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!
Code:
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
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
|
Accessing Word document variables from Excel Macro with VBA
|
new2vba |
Word, PowerPoint, Outlook, and Other Office Products |
0 |
09-03-2003 07:57 AM |
|
Creating Word Document from VB 6.0
|
Dean Crowe |
Word, PowerPoint, Outlook, and Other Office Products |
3 |
06-28-2003 07:00 PM |
|
QB to VB Conversion - By AIO
|
BillSoo |
Tutors' Corner |
0 |
08-06-2002 11:37 AM |
|
edit excel object in word document from VB
|
hatchetman |
Word, PowerPoint, Outlook, and Other Office Products |
2 |
07-18-2002 02:25 PM |
|
VB Word Application Document spacing a sizing problem
|
lamar_air |
Word, PowerPoint, Outlook, and Other Office Products |
8 |
05-24-2002 11:40 AM |
|
|
|
|
|
 |
|