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("Word.basic"
<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)), "000-00-0000"
<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 "TodaysDate", strTodaysDate<br>
objWord.SetFormResult "StudentSSN", strStudentSSN<br>
objWord.SetFormResult "StudentName", strStudentName<br>
objWord.SetFormResult "Address", strAddress<br>
objWord.SetFormResult "CityStateZip", strCityStateZip<br>
objWord.SetFormResult "Date", strSubmitDate<br>
objWord.SetFormResult "EntryType1", strEntryType1<br>
objWord.SetFormResult "EntryType2", strEntryType2<br>
<br>
<br>
Loop<br>
<br>
<br>
objWord.FileSaveAs ("C:\HENDO\Misc\OLE SAMPLE\RejectLetters " + strFileDate + ".doc"
<br>
<br>
Set objWord = Nothing<br>
<br>
<br>
End Sub<br>
<br>
<br>
<br>
<br>
<br>
<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("Word.basic"
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)), "000-00-0000"
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 "TodaysDate", strTodaysDate<br>
objWord.SetFormResult "StudentSSN", strStudentSSN<br>
objWord.SetFormResult "StudentName", strStudentName<br>
objWord.SetFormResult "Address", strAddress<br>
objWord.SetFormResult "CityStateZip", strCityStateZip<br>
objWord.SetFormResult "Date", strSubmitDate<br>
objWord.SetFormResult "EntryType1", strEntryType1<br>
objWord.SetFormResult "EntryType2", strEntryType2<br>
<br>
<br>
Loop<br>
<br>
<br>
objWord.FileSaveAs ("C:\HENDO\Misc\OLE SAMPLE\RejectLetters " + strFileDate + ".doc"
<br>
Set objWord = Nothing<br>
<br>
<br>
End Sub<br>
<br>
<br>
<br>
<br>
<br>
<br>