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 access objects of various Word files in VB6

Status
Not open for further replies.

2781

Technical User
Feb 26, 2002
21
BE
Hi,

I have a created a macro in Word to access various files in a directory, and to perform such actions on those files. This macro worked fine and the first lines are shown below.

When I want to use the same code in a stand-alone VB6 exe file, it does not seem to work anymore. An error variable Application not defined is shown. Any help?

Set fs = Application.FileSearch
With fs
.LookIn = "A:"
.FileName = "*.doc"
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then

For i = 1 To .FoundFiles.Count
strBestand = .FoundFiles(i)
Documents.Open FileName:=strBestand, ReadOnly:=True
' Roep een procedure aan die alle Prestaties opzoekt
Call SchrijfNaarArray

Documents(strBestand).Close SaveChanges:=wdDoNotSaveChanges
Next i
Else
MsgBox "There were no files found."
End If

Call KopieerNaarExcel

End With
End Sub
 
Hi, um where does the error occur? I can't tell what's wrong from what I see here, I've tried to access Word documents from VB as well, using some different methods, and I was getting weird errors messages. From what I've heard, apparently there are a lot of bugs in VB6 for Word automation, so that might be what's happening here. But there still might be something wrong in your code, since you are not getting weird run time errors like I was. There are some postes here that describe some of the bug errors, maybe you'd want to check them out(but forgot where they were, hehe, sorry, just run search on opening word doc in vb or something). Sorry I'm not much of help at all, and good luck.
 
Try addind this to the start of your code, you have to check the syntax.

dim app as application

set app = application.word
Set fs = app.FileSearch

The problem is VB doesn't know what application to use for the FileSearch function.
 
Thanks for your assistance, See also what I received from a similar question:
_______________

JohnYingling (Programmer) Mar 22, 2002
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


JohnYingling (Programmer) Mar 22, 2002
Start here.
Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top