Solved

Use of Microsoft Word Object

Posted on 2002-05-10
6
142 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
ID: 7001887
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
ID: 7001894
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
ID: 7001898
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
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 
LVL 12

Expert Comment

by:roverm
ID: 7001957
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
ID: 7002244
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
ID: 7002299
Thanks to you for "A" grade.
Glad to help.
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

809 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