J
jeremy.haynie
Here's the basic premise:
I created a workbook with a userform and openworkbook macros to load
the userform. I then wrote an add-in that simply opened up my workbook
from the tools menu. I forced a saveas so that users couldn't access
the original. If they canceled the saveas or userform then the
userform and my workbook (thisworkbook) would close.
If I open my workbook independently then everything works ok. When I
run the add-in and cancel the saveas or the userform I get a
"Application-Defined or Object-Defined Error". I've tried using "on
error resume next", but the error message still pops up. Although, the
workbook and userform do close, I still don't want the error message
to appear.
Any help would be appreciated.
Here is the code I'm using to close the userform and workbooks. Both
ways to close give the same error.
Is it the use of ThisWorkbook?
Thanks
Private Sub Cancel_Click()
CloseWorkbook = True
On Error Resume Next
ThisWorkbook.Close False
On Error Resume Next
Unload AutoComplete
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)
If CloseWorkbook = False Then Exit Sub
'skips if OK button is pressed on Userform
Application.DisplayAlerts = False
On Error Resume Next
ThisWorkbook.Close False
Application.DisplayAlerts = True
CloseWorkbook = True
End Sub
I created a workbook with a userform and openworkbook macros to load
the userform. I then wrote an add-in that simply opened up my workbook
from the tools menu. I forced a saveas so that users couldn't access
the original. If they canceled the saveas or userform then the
userform and my workbook (thisworkbook) would close.
If I open my workbook independently then everything works ok. When I
run the add-in and cancel the saveas or the userform I get a
"Application-Defined or Object-Defined Error". I've tried using "on
error resume next", but the error message still pops up. Although, the
workbook and userform do close, I still don't want the error message
to appear.
Any help would be appreciated.
Here is the code I'm using to close the userform and workbooks. Both
ways to close give the same error.
Is it the use of ThisWorkbook?
Thanks
Private Sub Cancel_Click()
CloseWorkbook = True
On Error Resume Next
ThisWorkbook.Close False
On Error Resume Next
Unload AutoComplete
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)
If CloseWorkbook = False Then Exit Sub
'skips if OK button is pressed on Userform
Application.DisplayAlerts = False
On Error Resume Next
ThisWorkbook.Close False
Application.DisplayAlerts = True
CloseWorkbook = True
End Sub