Solved

Use of Microsoft Word Object

Posted on 2002-05-10
6
140 Views
Last Modified: 2010-05-02
I have integrated Microsoft Word into my application and it is used to open a template, do various things to the template and then save it. It is also used to open a new document based on the template and then save that after reformatting, etc. This all works fine but only, it seems when Word 2000 is being used. It fails with '95 and '97. The object library I am using is the MSWORD9.OLB. I presume that for some reason this isn't compatible with earlier versions. I can probably live with this if I have to, but will I have the same problem with later versions of Word too? If it is possible to overcome this problem I would be grateful for advice., e.g., is is ppossible to use an earlier object library to ensure compitibility, and if so any ideas where I can find it? Thanks

As there are about 4 different questions here the points will reflect this. Thanks again.

Colin.
 
0
Comment
Question by:cbitservices
  • 4
6 Comments
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 200 total points
Comment Utility
If you use CreateObject("word.application") everything would works fine.
Do your development with a type library. When finish, remove it and use generic object variables for all word objects.
Doing so, while development, you have autolist members and others benefits.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
VB would take cares of create that word instance.
if you are using, for instance:
dim wdapp as new word.application
it sticks with your refernced library (8, 9 or 10)
but if you use
dim wdapp as bject
set wdapp=createObject("word.application")
is vb which will create correct object accoding to end user office installation.
Hope i was clear
PS: i don't know regarding Office95, sorry.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Also, take in mind that there are some funcionality that you could get with newer version but not with old one. different implementations for same matter could be an issue between version.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 12

Expert Comment

by:roverm
Comment Utility
Richie is correct, the best way to get a reference to word is using late binding. This way you never have to worry about versions.

When you develop your application you might use early binding by setting a reference to the OLB, so you have IntelliSense.

Here what I usually do to get any object (like word):

Public bNewWord As Boolean
Public oWord As Object

Public Function GetInstance() As Boolean

    'try to get a reference to an existing open instance of Word
    On Error Resume Next
    bNewWord = False
    Set oWord = GetObject("", "Word.Application")
    If Err.Number <> 0 Then
        'there was an error ==> no Word instance was opened yet, create it
        bNewWord = True
        Err.Clear
        Set oWord = CreateObject("Word.Application")
    End If
    oWord.Visible = True
    GetInstance = Not (oWord Is Nothing)
   
End Function

Public Function DestroyInstance() As Boolean

    'if we opened a new instance then quit Word
    If bNewWord Then oWord.Quit
    'destroy handle to it and free memory
    Set oWord = Nothing
   
End Function

D'Mzzl!
RoverM
0
 
LVL 1

Author Comment

by:cbitservices
Comment Utility
Thanks Richie,

I knew there was probably a simple answer; I just didn't know what it was! I know now though thanks to you! Thanks for a speedy response too!

Cheers,

Colin.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Thanks to you for "A" grade.
Glad to help.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now