K
Ken
I have a userform for which I disable the close button on the caption
to force people to use my close button. When I include a line to run
my close button in the following code I get an error when I close
Excel. The error does not pop up when the form and file close, only
afterward when I close Excel. Then I get Run Time Error 440,
Automation Error. I only get the options to End or Help. End clears
things up, Help is pretty useless.
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)
If CloseMode = 0 Then
Call CommandButton1_Click
Cancel = 1
End If
End Sub
Originally the functionality in the CommandButton1_Click code was in
the UserForm_QueryClose() code. I get the same result including it or
running it indirectly. I do not get the Automation error when exiting
Excel when the code is run from the close command button. This is all
the command button code is:
Private Sub CommandButton1_Click()
Dim x As Integer
'exit button
Unload Me
100
On Error GoTo 200
If Range("AutoClose").Value = "On" Then
ActiveWorkbook.Save
ActiveWorkbook.Close
End If
Exit Sub
200
x = MsgBox("can't save file right now. Close without saving?",
vbYesNo)
If x = 6 Then
ActiveWorkbook.Saved = True
ActiveWorkbook.Close
Else
GoTo 100
End If
End Sub
This just closes the file if a flag is set to do so. Sometimes the
network is slow and we get an error about the file being in use, so
the last part of the code deals with that.
I only get the automation error when closing Excel. It only happens
when I try to use my command button 1 code from the
UserForm_QueryClose code. Any ideas?
Thanks
Ken
to force people to use my close button. When I include a line to run
my close button in the following code I get an error when I close
Excel. The error does not pop up when the form and file close, only
afterward when I close Excel. Then I get Run Time Error 440,
Automation Error. I only get the options to End or Help. End clears
things up, Help is pretty useless.
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)
If CloseMode = 0 Then
Call CommandButton1_Click
Cancel = 1
End If
End Sub
Originally the functionality in the CommandButton1_Click code was in
the UserForm_QueryClose() code. I get the same result including it or
running it indirectly. I do not get the Automation error when exiting
Excel when the code is run from the close command button. This is all
the command button code is:
Private Sub CommandButton1_Click()
Dim x As Integer
'exit button
Unload Me
100
On Error GoTo 200
If Range("AutoClose").Value = "On" Then
ActiveWorkbook.Save
ActiveWorkbook.Close
End If
Exit Sub
200
x = MsgBox("can't save file right now. Close without saving?",
vbYesNo)
If x = 6 Then
ActiveWorkbook.Saved = True
ActiveWorkbook.Close
Else
GoTo 100
End If
End Sub
This just closes the file if a flag is set to do so. Sometimes the
network is slow and we get an error about the file being in use, so
the last part of the code deals with that.
I only get the automation error when closing Excel. It only happens
when I try to use my command button 1 code from the
UserForm_QueryClose code. Any ideas?
Thanks
Ken