cable
asked on
Accessing Word 97 in VB 5
I am having problems trying to get VB5 and Word97 to work togeather
using the Word.BASIC object like so:
Sub CopyToWord()
'Text deleted for Space in source code example
On Error GoTo OLE_Err
Dim obj_Word As Object
Set obj_Word = CreateObject("Word.Basic")
obj_Word.SetFormResult "client_number", lbl_ClientNum.Caption
obj_Word.SetFormResult "client_name", lbl_ClientName.Caption
obj_Word.SetFormResult "matter_number", lbl_MatterNum
obj_Word.SetFormResult "matter_name", lbl_MatterName.Caption
Set obj_Word = Nothing
Done
Exit Sub
OLE_Err:
MsgBox "ERROR:" & Str(Err) & " - " & Error$ & ". Copy aborted. ", ,
"OLE ERROR"
Set obj_Word = Nothing
Exit Sub
End Sub
I get "Error 509 - The SetFormResult command is not available because a document Window is not active. Copy aborted. " Yet the Word97 program is running and the Word97 document is open and active. I even put in an "Obj_Word.AppActivate 'Microsoft Word" command to make sure the Word Window is active, I even tried AppActivate "Microsoft Word". Same thing happened! I have the Word 8.0
references in my VB 5.0 code, and it is an external program run from a Word Macro using the Shell command to look up the client and matter information and then pass them back to Word97 using forms. The forms do exist and have the same lowercase bookmark names.
It should work as it is, yet it keeps claiming that the Word Document is not active, even when it is!
The Office97 VBA help is no good because VBA is very different from the VB 5.0 environment and the commands
are accessed differently. I can't find anything in Tech Net
or MSDN on it. Just the VBA way of doing it from Word 97,
which is useless to me, as I am doing it from VB 5.0
or at least trying to. It should be easy. but I am missing something.
Please help! Thanks.
using the Word.BASIC object like so:
Sub CopyToWord()
'Text deleted for Space in source code example
On Error GoTo OLE_Err
Dim obj_Word As Object
Set obj_Word = CreateObject("Word.Basic")
obj_Word.SetFormResult "client_number", lbl_ClientNum.Caption
obj_Word.SetFormResult "client_name", lbl_ClientName.Caption
obj_Word.SetFormResult "matter_number", lbl_MatterNum
obj_Word.SetFormResult "matter_name", lbl_MatterName.Caption
Set obj_Word = Nothing
Done
Exit Sub
OLE_Err:
MsgBox "ERROR:" & Str(Err) & " - " & Error$ & ". Copy aborted. ", ,
"OLE ERROR"
Set obj_Word = Nothing
Exit Sub
End Sub
I get "Error 509 - The SetFormResult command is not available because a document Window is not active. Copy aborted. " Yet the Word97 program is running and the Word97 document is open and active. I even put in an "Obj_Word.AppActivate 'Microsoft Word" command to make sure the Word Window is active, I even tried AppActivate "Microsoft Word". Same thing happened! I have the Word 8.0
references in my VB 5.0 code, and it is an external program run from a Word Macro using the Shell command to look up the client and matter information and then pass them back to Word97 using forms. The forms do exist and have the same lowercase bookmark names.
It should work as it is, yet it keeps claiming that the Word Document is not active, even when it is!
The Office97 VBA help is no good because VBA is very different from the VB 5.0 environment and the commands
are accessed differently. I can't find anything in Tech Net
or MSDN on it. Just the VBA way of doing it from Word 97,
which is useless to me, as I am doing it from VB 5.0
or at least trying to. It should be easy. but I am missing something.
Please help! Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.