LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ken Ken is offline
external usenet poster
 
Posts: 207
Default automation error when closing excel

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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compile error: Automation error in Excel 97 Geoff Excel Programming 3 July 1st 08 07:20 AM
Referencing CountA - Excel automation object not closing archerokie Excel Programming 5 October 10th 07 08:29 PM
help !!! please... closing excel application using automation No Name Excel Programming 3 January 30th 04 03:58 PM
VB Excel Automation Error Sasanka Pinidiya Excel Programming 0 August 26th 03 08:11 AM
Error while closing Excel Daniel Altman Excel Programming 1 August 13th 03 06:16 PM


All times are GMT +1. The time now is 03:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"