Need to close Word when it won't quit.

N

Nigel Bufton

My application pushes Word to the limit. It can produce documents that are
hundreds of pages long including many pictures and many shapes (lines,
rectangles) to create charts. With a large document, Word will "crash"
(cease to process any more directives) with "memory or disk problem".

Because the documents are created with many sections, the application saves
the document at the end of each section.

It error traps Word crashing, at which point I need it to quit Word and
start it afresh - resuming from the start of the section in which it
crashed.

All of the logic works fine, except in many cases a Quit or Close directive
fails because Word has reached the end of its tether.

Is there a simple way to close the crashed instance of Word, or do I need to
use the Windows API to kill the WinWord process. If so, is there any easy
way of determining which is the process in question if there are more than
one WinWord process running?

Thanks for any guidance.

Nigel
 
D

Doug Robbins - Word MVP

Do you have

[documentobject].UndoClear

in your code anywhere. If not, I would insert that after each section is
saved and see if it makes any difference.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
N

Nigel Bufton

Doug Robbins - Word MVP said:
Do you have

[documentobject].UndoClear

in your code anywhere. If not, I would insert that after each section is
saved and see if it makes any difference.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

Yes, I have UndoClear after each save. The complexity of the very large
documents will inevitably cause a Word crash sooner or later. It is
recovering from the crash that is the issue that I am working. Currently
I've implemented brute-force killing of all winword.exe process(es) before
commencing an extension document from the section in which Word crashed. I
was seeking something more elegant.

Nigel
 
A

alborg

Hi Nigel:

I used to have this problem, except it occurred when I linked Word to
Access, leaving at the end numberous Access instances. The trick to get rid
of these instances of Access/Word is to put the following code into the
ThisDocument code pane as such-
http://i38.photobucket.com/albums/e103/alborgmd/Software/CloseWord.png

What this simple process does is to use the GetObject method to find
instances of, in your case it would be "Word.Application", and if still
running, you quit the instance. The "GoTo Repeat" continues to run the code
until all instances are removed.

Here is how your code should look like:

Private Sub Document_Close()
On Error GoTo Err_GoToWord_Click
Dim appWord As Object 'or Word.Application
Dim Wordwasnotrunning As Boolean ' Flag for final release.
On Error Resume Next
Repeat:
Set appWord = GetObject(, "Word.Application")
AppActivate "Microsoft Word"
If err = 0 Then
'Word is still running
Wordwasnotrunning = True
appword.Quit
Set appword = Nothing
GoTo Repeat
End If
End Sub

That should do the trick!

Cheers,
Al

Al Borges MD
www.msofficeemrproject.com

Nigel Bufton said:
Doug Robbins - Word MVP said:
Do you have

[documentobject].UndoClear

in your code anywhere. If not, I would insert that after each section is
saved and see if it makes any difference.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

Yes, I have UndoClear after each save. The complexity of the very large
documents will inevitably cause a Word crash sooner or later. It is
recovering from the crash that is the issue that I am working. Currently
I've implemented brute-force killing of all winword.exe process(es) before
commencing an extension document from the section in which Word crashed. I
was seeking something more elegant.

Nigel


.
 
A

alborg

Ooops- one error in your version of the code that I listed:

Convert "appWord.Quit" to "appWord.Application.Quit" since in this case
appWord was declared as an object ("Dim appWord As Object")-
'-------------------------------------------------------
Private Sub Document_Close()
On Error GoTo Err_GoToWord_Click
Dim appWord As Object 'or Word.Application
Dim Wordwasnotrunning As Boolean ' Flag for final release.
On Error Resume Next
Repeat:
Set appWord = GetObject(, "Word.Application")
AppActivate "Microsoft Word"
If err = 0 Then
'Word is still running
Wordwasnotrunning = True
appWord.Application.Quit
Set appword = Nothing
GoTo Repeat
End If
End Sub
'-------------------------------------------------------
Cheers,
Al

Nigel Bufton said:
Doug Robbins - Word MVP said:
Do you have

[documentobject].UndoClear

in your code anywhere. If not, I would insert that after each section is
saved and see if it makes any difference.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

Yes, I have UndoClear after each save. The complexity of the very large
documents will inevitably cause a Word crash sooner or later. It is
recovering from the crash that is the issue that I am working. Currently
I've implemented brute-force killing of all winword.exe process(es) before
commencing an extension document from the section in which Word crashed. I
was seeking something more elegant.

Nigel


.
 
N

Nigel Bufton

Thanks, I'll try it.

Nigel

alborg said:
Ooops- one error in your version of the code that I listed:

Convert "appWord.Quit" to "appWord.Application.Quit" since in this case
appWord was declared as an object ("Dim appWord As Object")-
'-------------------------------------------------------
Private Sub Document_Close()
On Error GoTo Err_GoToWord_Click
Dim appWord As Object 'or Word.Application
Dim Wordwasnotrunning As Boolean ' Flag for final release.
On Error Resume Next
Repeat:
Set appWord = GetObject(, "Word.Application")
AppActivate "Microsoft Word"
If err = 0 Then
'Word is still running
Wordwasnotrunning = True
appWord.Application.Quit
Set appword = Nothing
GoTo Repeat
End If
End Sub
'-------------------------------------------------------
Cheers,
Al

Nigel Bufton said:
My application pushes Word to the limit. It can produce documents
that
are hundreds of pages long including many pictures and many shapes
(lines, rectangles) to create charts. With a large document, Word
will
"crash" (cease to process any more directives) with "memory or disk
problem".

Because the documents are created with many sections, the application
saves the document at the end of each section.

It error traps Word crashing, at which point I need it to quit Word
and
start it afresh - resuming from the start of the section in which it
crashed.

All of the logic works fine, except in many cases a Quit or Close
directive fails because Word has reached the end of its tether.

Is there a simple way to close the crashed instance of Word, or do I
need
to use the Windows API to kill the WinWord process. If so, is there
any
easy way of determining which is the process in question if there are
more than one WinWord process running?

Thanks for any guidance.

Nigel
Doug Robbins - Word MVP said:
Do you have

[documentobject].UndoClear

in your code anywhere. If not, I would insert that after each section
is
saved and see if it makes any difference.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

Yes, I have UndoClear after each save. The complexity of the very
large
documents will inevitably cause a Word crash sooner or later. It is
recovering from the crash that is the issue that I am working. Currently
I've implemented brute-force killing of all winword.exe process(es)
before
commencing an extension document from the section in which Word crashed.
I
was seeking something more elegant.

Nigel


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top