Using VB6 application to Update a Word File

B

Brian Wojo

Forgive my niativity, but I do not understand how to use VB 6 and build a
pure VB application (not VBA inside of Word as a macro) to update a Word
document file. I have a VB6 application that I want to use to fill in fields
of an existing Word document, then store it as a new file. Do I need to add
a particular library or module to VB to be able to do this. If I do a simply
declaration such as

Dim objWordApp as Word.Application

I get an error that it is a non-declared user type. Do I need to use API
calls to do such things? Do I need to add in a particular library? I guess
I'm uncertain of the difference between using VBA to create a macro and using
pure VB6 to control a word document. Can anyone point me in the right
direction to get started.
Thanks.
Brian
 
A

Anand.V.V.N

Hi Brain,
In Visual Basic choose refrence, probably is Word 8.0 or something like
that, you need to add that refrence to your Visual Basic Project amd it
should work.

Hope you found this useful and I hope it worked.
Let me know
Anand
 
J

Jezebel

You can use early binding or late binding. (Both explained in general in
VB's documentation)

With early binding you add the Word library to the VB project references.
Then create your reference to Word using

Dim objWordApp as Word.Application

Set objWordApp = Word.Application --> returns a reference to an
existing instance of Word if any, or throws a trappable error if there is
not such instance, or

Set objWordApp = new Word.Application --> creates a new instance of
Word


With late binding, you use

Dim objWordApp as object
set objWordApp = GetObject(,"Word.Application")
or
Set objWordApp = CreateObject("Word.Application")


Early binding is easier to program because you get the intellisense to help
with the syntax and you can declare your variables as specific Word elements
(Range, Paragraph, etc), and it's also slightly more efficient to run; but
it can make distribution more difficult if you're dealing with users with
different versions of Word. If you use late binding, all your objects are
declared as objects, so any errors you make with properties and methods
don't get picked up till you try to run it. A common practice is to develop
the app using early binding, then switch to late binding to create the
distribution version. Bear in mind that you're not allowed to distribute the
Word library itself with your compiled application.
 
B

Brian Wojo

Thanks so much. That did the trick. I'm a decent (not great) vb programmer,
but have never programmed another Office application using VB. Now I assume
I can use VBA methods, properties, etc.. to control a Word file through a
pure VB application. Is that correct? Thanks so much for all the help.
 
A

Anand.V.V.N

Hi,

You welcome, I am gald that it worked. Yes you can use all theword
properties and methods in VB.

Let me know if you need anything else.

Anand
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top