Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    Oct 2002
    Location
    Stevenage, Bedfordshire, England
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word Hanging after Close (Word 2000/ VBA)

    Hi,
    I've got a problem with Word hanging, and l can't track down what's happening with it.
    This is the setup:
    I have a template with a reference to a VB project which contains various forms, each of which can be called from a toolbar l have created in the template. All is fine, everything works as it should, unless you try to close Word using the 'x' exit button on the title bar ( or from 'file/exit'), at which point the document closes, but the application window hangs.
    I have a class module called 'ThisApplication', which has a 'oApp_DocumentBeforeClose' event, which runs OK, and the 'Document_Close' event in 'This Document' also runs through fine. Something is happening after this point, or rather, not happening, that l can't track down.
    I believe it's probably an object that's not closing down properly, but l've been through the code in both the template and the Visual basic project line-by-line (no small task!), making sure every time an object is set, there's a corresponding 'set xxx = nothing'.
    If it's not a stubborn object hanging around, what else could it be? If l simply open a document with the template attached, and close it down again, without calling one of the forms in my external VB app, all is fine.
    Is there any code that will close any open objects (a slim chance, l'm sure!) - none of them are global anyhow.

  2. #2
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Hanging after Close (Word 2000/ VBA)

    I don't have any concrete answers, just observations. It sure sounds like an unreleased object to me.

    I would suspect that it is the object holding the pointer to your VB app.

    You are right, this like this are hard to track down. I had one like this that took me a few days to discover. Excel kept crashing when exiting after I used a COM Add-In. It turned out that I forgot to release one object and then released the objects in the wrong order.

    So not only is it important to release them, but the need to be released in the opposite order of being created.
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Hanging after Close (Word 2000/ VBA)

    What's your OS?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Hanging after Close (Word 2000/ VBA)

    The reason I ask, about the OS, that is, is you may still have a Word process in memory.

    Win9x has a problem that way and usually Win2k,XP will remove any terminated apps.

    Check you task list after a Word crash and make sure there are no winword.exe's
    floating around.

    Since you have deduced that accessing one of your forms causes the problem, you
    definitely have rouge code doing something unkind.

    It would be helpful to see your app event code. I suspect your "exit" events or any
    Word Command subs:

    FileExit, FileClose, DocClose, oapp_DocumentBeforeSave, ...BeforeClose, etc.

    ...or it could be a corrupted Normal.dot...
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  5. #5
    New Lounger
    Join Date
    Oct 2002
    Location
    Stevenage, Bedfordshire, England
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Hanging after Close (Word 2000/ VBA)

    ---need to be released in the opposite order of being created--- I haven't checked this, though having said that, there's only the one object relating to the external app...
    I'm running Windows 2000.
    If l check the list of processes while Word is hanging, there is a single winword, which l assumed to be related to the hanging Word instance. If l end this
    process, the Word window closes too.
    I did have a problem with Word a few days ago, after deleting the normal.dot, and starting word with /a, that resolved itself.
    I also checked that my PC had all the latest updates. Three hours and 30-odd updates later, no change...

    In ThisDocument, l have:

    Private Sub Document_Close()
    On Error GoTo ErrorHandler

    Dim bLetterTemplate As Boolean
    Dim iCount As Integer
    10
    ' remove the 'print for n only' submenu
    bLetterTemplate = False
    20
    ' see if the Letters menu bar is present
    With CommandBars
    For iCount = 1 To .Count
    If .Item(iCount).Name = "Letters Menu Bar" Then
    bLetterTemplate = True
    Exit For
    End If
    Next iCount
    End With
    30
    ReInstateMRUList
    40
    EnableMailMergeToolbar
    50
    'prevent word from asking whether we want to save Letters.Dot
    Application.ActiveDocument.AttachedTemplate.Saved = True
    60
    '25/2 cf swapped these two lines around
    If Word.Documents.Count = 1 Then
    61
    MsgBox "closing "
    62
    gobjForms.Close
    63
    'Set gobjForms = Nothing
    End If
    64
    ' if this is the only open Word Letters doc, close activewindow, ie, quit Word
    If Application.Documents.Count = 1 Then Application.ActiveWindow.Close

    Exit Sub

    ErrorHandler:
    TopLevelErrHan sbMODULE & ".Document_Close", , Erl
    End Sub

    Some of this code is not as it was, as l've been messing it around trying to find out what's going wrong. For example, what difference does a '.close' over 'set xxx = nothing' make? Will 'Application.ActiveWindow.Close' force it to close, etc.

    In NewMacros, among others:

    Dim oAppClass As New ThisApplication

    Public Sub AutoExec()
    On Error GoTo ErrorHandler

    10
    Set oAppClass.oApp = Word.Application
    20
    Set gobjForms = New ExternalForms.CFrmOpen <--- my external app
    If IsNothing(gobjForms) Then
    30
    Set gobjForms = New ExternalForms.CFrmOpen
    End If

    Exit Sub
    ErrorHandler:
    NonTopLevelErrHan sbMODULE & "AutoExec", , Erl
    End Sub

    And finally, in ThisApplication:

    Public WithEvents oApp As Word.Application

    Private Sub oApp_DocumentBeforeClose(ByVal Doc As Document, Cancel As Boolean)
    On Error GoTo ErrorHandler
    Dim lResponse As VbMsgBoxResult
    10
    If ActiveDocument.Saved = False And ActiveDocument.Words.Count > 1 Then
    lResponse = MsgBox("Save Changes before Closing?", vbYesNoCancel, "Word Link")
    If lResponse = vbYes Then
    gobjForms.ShowSaveLetter
    If ActiveDocument.Saved = False Then
    Cancel = True
    Exit Sub ' if user has chosen not to save from the save dialog
    End If
    ElseIf lResponse = vbCancel Then
    Cancel = True
    Exit Sub
    End If
    20
    ActiveDocument.Saved = True
    30
    ' 25/2 cf
    If Application.Documents.Count = 1 Then
    Word.Application.Quit SaveChanges:=wdDoNotSaveChanges
    Else
    Application.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
    End If
    ElseIf Application.Documents.Count = 1 Then
    40
    ActiveDocument.Saved = True
    Word.Application.Quit SaveChanges:=wdDoNotSaveChanges
    50
    End If
    Exit Sub
    ErrorHandler:
    NonTopLevelErrHan sbMODULE & ".DocumentDeforeClose", , Erl

    End Sub


    I hope this makes sense, l'm now going to take a look and see if l can find any code to close all 'undead' objects. Just a thought.

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Word Hanging after Close (Word 2000/ VBA)

    Yikes, I find that a bit hard to read. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    Using File>Exit or the X button might not be running the procedures you have so carefully put together in your document template. To make sure that the code you want to run runs, you might need a macro in Normal.dot or another global template instead of or in addition to your template macros. This is just a guess.

    If you create some simple "stub" macros that write to a text file or display MsgBoxes, can you determine whether and when your different event procedures are getting run when you use File>Exit or the X button?

  7. #7
    New Lounger
    Join Date
    Oct 2002
    Location
    Stevenage, Bedfordshire, England
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Hanging after Close (Word 2000/ VBA)

    Uh, sorry, l found it hard to read and l wrote the stuff, lol!

    Eventually l found the problem - a global object in my external .dll that wasn't being set to nothing (l must have missed it when l went through the code, there was just so much of it!). Added the set to nothing code line, and Word was happy once again.
    Thanks for your help.

Posting Permissions

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