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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Word Automation With Office 97???

Status
Not open for further replies.

dbrooks74

Programmer
Nov 13, 2001
105
US
I have Office 2000 and parts of XP on my PC however because some of my users are using Office 97 it crashes on their PCs. Can someone help? I am using Visual Basic 6.0 with a reference to "Microsoft Word 9.0 Object Library" because I cannot find a lower version. Also I have a line which reads Set objWord = CreateObject("Word.Application") should this be changed to reflect that I want Word 97? How would I do this?

Can someone help?

Thanks!
 
You must use "late-binding", that is "As Object", for all Office objects for compiling to production.
Dim obWord As object '''Word.Application
and use, as you have, Set xxx = CreateObject rather than As New.

In test however you can use
Dim objWord As Word.Application ' etc
and the Type Library so you can use Intellisense.
Leave the Type Library Reference in the final compile to pick up wd constants but be sure that all Office objects are defined As Object.
Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
good call JohnYingLing. I didn't notice he was using createobject.
sdraper
 
My Program no longer crashes which is good but I now get an error that says..."Error 448 Named Argument not found". Any ideas?
 
Okay first you can call Word.Application like this

CreateObject("Word.Application.9") or CreateObject("Word.Application.10") or whatever version of Word you are using. I believe 97 is 8 So it would "Word.Application.8".

Okay now. As for 448 take a look at the line of code that you are having this problem, my guess, and this is a just a guess the problem is with a word method. If that is the case then you will need to change the method call b/c the method is implemented differently in different versions. This is known to be the case in Microsoft, ignoring polymorphism is easy when you are the big dog :).

If you are having trouble finding the line error may I suggest erl (A very under used method)
 
This is the code I am using. Does anything look off?


Dim objWord as Object

Set objWord = CreateObject("Word.Application.8")
'Set the Word Document To Not Visible
objWord.Visible = False

'Set the document object to the next object
objWord.Documents.Open sFullPath, ReadOnly:=True, Visible:=True

'Minimize the window
objWord.WindowState = wdWindowStateMinimize

With objWord.Selection.Find
.Text = txtEventID
.Forward = True
.Execute
If .Found = True Then
bFound = True
End If
End With

If bFound Then
Msgbox "FOUND!"
objWord.Selection.MoveRight Unit:=wdCharacter, Count:=1

With objWord.Selection.Find
.Text = "OBX"
.Forward = True
.Execute
End With

objWord.Selection.MoveRight Unit:=wdCharacter, Count:=1
With objWord.Selection.Find
.Text = "|"
.Forward = True
.Execute
End With

objWord.Selection.MoveRight Unit:=wdCharacter, Count:=1
With objWord.Selection.Find
.Text = "|"
.Forward = True
.Execute
End With

objWord.Selection.MoveRight Unit:=wdCharacter, Count:=1
With objWord.Selection.Find
.Text = "|"
.Forward = True
.Execute
End With

objWord.Selection.MoveRight Unit:=wdCharacter, Count:=1
objWord.Selection.MoveRight Unit:=wdCharacter, Count:=23, Extend:=wdExtend
'objWord.Selection.Copy
txtResult.Text = txtResult.Text & objWord.Selection.Text & vbNewLine
Else
txtStatus.Text = txtStatus.Text & vbNewLine & "Not Found!"
End If
 
Never mind I figured it out. For anyone who cares all I had was a problem where I set the visible property on open and I shouldn't have.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top