Results 1 to 3 of 3

Thread: Closing Microsoft Word : problem using the Word.Global functions

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    38

    Unhappy

    Hello there, could (please) anyone help me with this annoying problem?

    I'm making an application that has to put data on a simple Microsoft Word 2000 document. I use this code for it...

    --Begin Code--
    dim objWrdApp As Word.Application

    On Error Resume Next

    Set objWrdApp = GetObject(, "Word.Application.9")
    If Err.Number = 429 Then
    Set objWrdApp = CreateObject("Word.Application.9")
    Err.Clear
    End If

    --End Code--

    My application runs well until I -close- Microsoft Word myself or by code...

    When I try to use the Word reference again in the same application (I didn't close it and it has ran the above declarations again), it gives me this Error message:

    **********
    Run-time error '462':
    The remote server machine does not exist or is unavailable
    **********

    My application craches on all the code that uses the Word(.Global) functions, all the rest is OK.

    -Begin Code-
    With .ActiveDocument.PageSetup
    .LineNumbering.Active = False
    .Orientation = wdOrientPortrait
    .TopMargin = CentimetersToPoints(0.2) <-- CRASH!
    .BottomMargin = 7.1 '0.25 cm <-- Works fine without the function...
    -End Code-

    I don't know what the problem is but I need a solution QUICK cause I've got to make a deadline... (AAaargh)

    Can Someone help me?

    Thank You for Your time!
    Bart Lipkens


  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Well you're using GetObject and that's OK but then you only use CreateObject if Error 429 was raised. Change the code to this:
    Code:
    Dim objWrdApp As Word.Application
    
    On Error Resume Next
    Set objWrdApp = GetObject(, "Word.Application.9") 
    If Err.Number <> 0 Then 
        Err.Clear 
        Set objWrdApp = CreateObject("Word.Application.9") 
    End If
    Good luck!

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    38

    Unhappy

    Joacim, thank You for your response, but it still doesn't work... It's just like he doesn't want to 'reinitialise' the Word reference when I've closed Word myself...

    I can open Word again by code, put data in it, but when I want to use the Word(.Global) functions like the CentimetersToPoints function it just crashes, very stupid and I don't know why...




    [Edited by balip on 08-30-2000 at 03:11 AM]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width