Get error "Word has encountered a problem..." when using File...New macro to toggle on/off Windows i

P

Pat Sullivan

Hi,
I get the error "Word has encountered a problem and needs to close. We are
sorry for the inconvenience." when I create a document from a template using
File...New. The error occurs after the AutoNew subroutine ends.

If I double-click the template file in Windows Explorer, the AutoNew
subroutine works fine. Opening a doucment that is attached to the template
(running the AutoOpen subroutine using the same code) works fine also.

I am using Word 2003, and the macro checks if the "Windows in Taskbar" is
checked. If so, I want to uncheck it so that a Userform that opens multiple
documents will remain in view. At the end, I want to re-check "Windows in
Taskbar", if that was the original user setting.

Does anyone know what is causing this behaviour & if there is a way around
it?

This is the code used in the template file .....

Public ShowTasks As Boolean
Dim WordVer As String
Dim VerNum As Double
Dim VerInt As Integer

Sub AutoOpen()
Call TurnOffSDI ' so Userform remains in view
'
' Code to ... Load Userform & open multiple documents
'
Call TurnOnSDI ' return to original user setting
End Sub

Sub AutoNew()
Call TurnOffSDI ' so Userform remains in view
'
' Code to ... Load Userform & open multiple documents
'
Call TurnOnSDI ' return to original user setting
End Sub

Sub TurnOffSDI()
' If later than W2000 (or version 9.0)- turn off the SDI feature
ShowTasks = False
WordVer = Application.Version ' get Word version#
VerNum = Val(WordVer) ' convert to decimal number & remove
possible alpha suffix(i.e. for SRs prior to W2000)
VerInt = Int(VerNum) ' truncate to get version#
(11=W2003,10=W2002,9=W2000,8=W97,7=W95)
If VerInt > 9 Then
Call SDIOffWord10 ' call if version later than Word2000
End If
End Sub

Sub TurnOnSDI()
' If later than W2000 (or version 9.0)- turn on the SDI feature
WordVer = Application.Version ' get Word version#
VerNum = Val(WordVer) ' convert to decimal number
VerInt = Int(VerNum) ' truncate to get version#
(11=W2003,10=W2002,9=W2000,8=W97,7=W95)
If VerInt > 9 Then
Call SDIOnWord10 ' call if version later than Word2000
End If
End Sub

Sub SDIOffWord10()
' ShowTasks is true if user setting at Tools|Options|View...Windows in
Taskbar is checked
If Application.ShowWindowsInTaskbar Then ShowTasks = True
Application.ShowWindowsInTaskbar = False
End Sub

Sub SDIOnWord10()
' ShowTasks is true if user setting at Tools|Options|View...Windows in
Taskbar is checked
If ShowTasks Then Application.ShowWindowsInTaskbar = True
End Sub
 
W

Word Heretic

G'day "Pat Sullivan" <[email protected]>,

You need to use an Ontime command to delay the load of the user form
until AFTER the doc has loaded and Word has done its housekeeping on
it.

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Pat Sullivan reckoned:
 
P

Pat Sullivan

Hi,
Since the problem occurs during the End statement in the AutoNew subroutine,
I'm not sure how the Ontime command would help.
Pat
 
W

Word Heretic

G'day "Pat Sullivan" <[email protected]>,

Ok. When Word opens, it auto-runs the Execs. BUT - at this point it
has NOT finished 'playing' with the document. So it simply aint ready
for OUR stuff (eg userforms). In order to show a form etc, we have tyo
let Word have a good play with the document. The Ontime command
achieves this for us. Try trusting my advice and see what happens.

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Pat Sullivan reckoned:
 

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