Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing data from VB6 to a MS Word template 1

Status
Not open for further replies.

mhendo59

Programmer
Jan 18, 2000
5
0
0
US
With no previous knowledge of passing data to MS Word, I am attempting to pass data from an existing VB application to a template I've created in MS Word.<br>
<br>
I need my application to loop through and pass data to the bookmarks I have set up in the template. Once a record's data has been passed, I want to set a manual page break and loop to the next record, pass that records info, set a page break, loop to the next and so on... In the end I need to be left with a single word document consisting of X number of pages.<br>
<br>
So far I figured out how to open the template and write to the word document but I can't figure out:<br>
1) how to set the manual page break after each record.<br>
2) how to regenerate the template after the page break and print the new records info without changing the previous record's info.<br>
<br>
Attached at the bottom is the code.<br>
<br>
Any help is greatly appreciated.<br>
<br>
-Marc <br>
==========================================<br>
Set objWord = CreateObject(&quot;Word.basic&quot;)<br>
objWord.appShow<br>
objWord.FileNew Template:=ReportTemplate<br>
<br>
<br>
Open strCCRejectFile For Input As #1<br>
Do While Not EOF(1)<br>
Line Input #1, CCInputLine<br>
<br>
'assign values from text file<br>
strStudentSSN = Format(Trim(Left(CCInputLine, 11)), &quot;000-00-0000&quot;)<br>
strStudentName = Trim(Mid(CCInputLine, 32, 43))<br>
strSubmitDate = Trim(Mid(CCInputLine, 14, 18))<br>
strAddress = Trim(Mid(CCInputLine, 75, 65))<br>
strCityStateZip = Trim(Mid(CCInputLine, 140, 47))<br>
strEntryType = Trim(Mid(CCInputLine, 12, 2))<br>
<br>
<br>
objWord.SetFormResult &quot;TodaysDate&quot;, strTodaysDate<br>
objWord.SetFormResult &quot;StudentSSN&quot;, strStudentSSN<br>
objWord.SetFormResult &quot;StudentName&quot;, strStudentName<br>
objWord.SetFormResult &quot;Address&quot;, strAddress<br>
objWord.SetFormResult &quot;CityStateZip&quot;, strCityStateZip<br>
objWord.SetFormResult &quot;Date&quot;, strSubmitDate<br>
objWord.SetFormResult &quot;EntryType1&quot;, strEntryType1<br>
objWord.SetFormResult &quot;EntryType2&quot;, strEntryType2<br>
<br>
<br>
Loop<br>
<br>
<br>
objWord.FileSaveAs (&quot;C:\HENDO\Misc\OLE SAMPLE\RejectLetters &quot; + strFileDate + &quot;.doc&quot;)<br>
<br>
Set objWord = Nothing<br>
<br>
<br>
End Sub<br>
<br>
<br>
<br>
<br>
<br>
<br>

 
<br>
Quick question,<br>
<br>
If I wanted to declare objWord as Word.Basic, what object must I reference?<br>
<br>
I found that when you declare a variable and use the New keyword to create an instance of it, you end up getting more help than when using the CreateObject command.<br>
<br>
As for the problem you're having, it seems that you must create multiple documents based on the template then somehow merge those documents.<br>
<br>
-- OR --<br>
<br>
Use mailmerge by putting your data into an Access table rather than a text file.<br>
<br>
I might be way off target for what you need but anyway, food for thought!<br>
<br>
Tarek<br>
<br>
P.S. I would like to know what I need to reference to declare objWord as Word.Basic
 
Tarek,<br>
<br>
I have &quot;objWord&quot; declared as an object but failed to include it in the attached code. <br>
<br>
Dim objWord As Object<br>
<br>
I will try to write the the data into Access rather than a text file and see how that works.<br>
<br>
Thanks.
 
<br>
Marc,<br>
<br>
Declaring objWord as Object is still considered &quot;late binding&quot; vs. declaring it, for example, as Word.xxx which is considered &quot;early binding&quot;. Declaring the object as a specific type helps me a great deal as I'm typing the code. For example, if I type objWord followed by a period &quot;.&quot; VB drops down a list of available properties and methods from there I can usually find what I need. Declaring objWord as Object does not give me any help.<br>
<br>
So, now in order to declare objWord as a specific object, I must make a reference to a type library of some sort (click Project -&gt; References) -- the question is, which object do I reference? I tried Microsoft Word 8.0 Object Library which gives me &quot;Word&quot; as an object type but &quot;Word.Basic&quot; doesn't seem to be there!!!<br>
<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top