Solved

Accessing Word 97 in VB 5

Posted on 1997-08-04
1
323 Views
Last Modified: 2012-06-21
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.

0
Comment
Question by:cable
1 Comment
 
LVL 3

Accepted Solution

by:
ChrisLewis earned 50 total points
ID: 1429619
You no longer use a Word.Basic object in Word 97.  Word 97 has a totally new object structure, so everything you knew about word 95 is now, well, worthless...  Thank you MS.

Look in the help file for the object structure of a Word 97 Document.  

What I think you have to do is to create a document obejct and use the Documents.Open method to open a document, then
use the ActiveDocument.FormFields(YourFieldNameHERE).Result
command

Take a look at the Word 97 VBA help and the Converting Wordbasic to VBA section

Hope this helps...

CHRIS

0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual Basic Excel Formatting error 4 106
Updates not working for MS Windows 7 12 166
VBA Shell can't Find Word document 11 94
MsgBox 4 61
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question