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!

How to convert a Word macro to a VB program: Object Variable problem?? 1

Status
Not open for further replies.

2781

Technical User
Feb 26, 2002
21
BE
Hi there,

I wish to convert a macro which works fine to a stand-alone VB6 program.

The first line in the macro read: Set fs = Application.Search

In the stand-alone programme however, it returns an error: Application not defined as Variable. With some slight syntax variations, it says Object not defined.

I guess the problem is how to reference in visual Basic an object variable that comes from another programme.

Could the solution lie in using:

Private Statement WithEvents, or New - and how do you use this. Or should the solution be sought elsewhere.

Thanks
 
In word, the application object is automatic and already defined. You will need.
Dim objWord As Object
Set objWord = CreateObject("Word.Application"

If you refer to Documents you will now need
objWord.Documents.

If you want to distribute this to people with different versions of Word from yours, you will need to use "late binding" i.e. "As Object" rather than "As Word.Apllication". The same goes for any other Word objects. You can still refer to a Word Object library to pick up constants (Enums).

Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Many, many thanks.

as an amateur user, it is only since a few weeks that I am on this forum, and I find it really amazingly useful. It is amazing what people can do for each. For example, since a long time I was looking for a reference like one you just gave>

One more small question:

You taught how to create an object for one Word file. Which object does one need to create to search all Word type (*.doc) files in a particular directory.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top