×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Passing data from VB6 to a MS Word template

Passing data from VB6 to a MS Word template

Passing data from VB6 to a MS Word template

(OP)
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.

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.

So far I figured out how to open the template and write to the word document but I can't figure out:
1) how to set the manual page break after each record.
2) how to regenerate the template after the page break and print the new records info without changing the previous record's info.

Attached at the bottom is the code.

Any help is greatly appreciated.

-Marc
==========================================
Set objWord = CreateObject("Word.basic")
objWord.appShow
objWord.FileNew Template:=ReportTemplate


Open strCCRejectFile For Input As #1
Do While Not EOF(1)
Line Input #1, CCInputLine

'assign values from text file
strStudentSSN = Format(Trim(Left(CCInputLine, 11)), "000-00-0000")
strStudentName = Trim(Mid(CCInputLine, 32, 43))
strSubmitDate = Trim(Mid(CCInputLine, 14, 18))
strAddress = Trim(Mid(CCInputLine, 75, 65))
strCityStateZip = Trim(Mid(CCInputLine, 140, 47))
strEntryType = Trim(Mid(CCInputLine, 12, 2))


objWord.SetFormResult "TodaysDate", strTodaysDate
objWord.SetFormResult "StudentSSN", strStudentSSN
objWord.SetFormResult "StudentName", strStudentName
objWord.SetFormResult "Address", strAddress
objWord.SetFormResult "CityStateZip", strCityStateZip
objWord.SetFormResult "Date", strSubmitDate
objWord.SetFormResult "EntryType1", strEntryType1
objWord.SetFormResult "EntryType2", strEntryType2


Loop


objWord.FileSaveAs ("C:\HENDO\Misc\OLE SAMPLE\RejectLetters " + strFileDate + ".doc")

Set objWord = Nothing


End Sub






RE: Passing data from VB6 to a MS Word template


Quick question,

If I wanted to declare objWord as Word.Basic, what object must I reference?

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.

As for the problem you're having, it seems that you must create multiple documents based on the template then somehow merge those documents.

-- OR --

Use mailmerge by putting your data into an Access table rather than a text file.

I might be way off target for what you need but anyway, food for thought!

Tarek

P.S. I would like to know what I need to reference to declare objWord as Word.Basic

RE: Passing data from VB6 to a MS Word template

(OP)
Tarek,

I have "objWord" declared as an object but failed to include it in the attached code.

Dim objWord As Object

I will try to write the the data into Access rather than a text file and see how that works.

Thanks.

RE: Passing data from VB6 to a MS Word template


Marc,

Declaring objWord as Object is still considered "late binding" vs. declaring it, for example, as Word.xxx which is considered "early binding". 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 "." 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.

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 -> References) -- the question is, which object do I reference? I tried Microsoft Word 8.0 Object Library which gives me "Word" as an object type but "Word.Basic" doesn't seem to be there!!!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close