Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Word, PowerPoint, Outlook, and Other Office Products > Need help filling in a word document from VB


Reply
 
Thread Tools Display Modes
  #1  
Old 11-26-2003, 09:37 PM
Kebie Kebie is offline
Newcomer
 
Join Date: Nov 2003
Posts: 3
Post 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.
Reply With Quote
  #2  
Old 11-27-2003, 07:31 PM
Kebie Kebie is offline
Newcomer
 
Join Date: Nov 2003
Posts: 3
Default

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.
Reply With Quote
  #3  
Old 11-29-2003, 12:22 AM
Kebie Kebie is offline
Newcomer
 
Join Date: Nov 2003
Posts: 3
Default

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
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

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

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->