Runtime Error 13 on Application.Quit

Drofidnas

Board Regular
Joined
Jun 30, 2004
Messages
126
This is more of an annoyance than anything.
I have a form which generates an email and then quits Excel.

The macro to run the code is on a shape, linked to the code.

If I am out of a cell and anywhere on the worksheet it is fine.

But if I am "live" in a cell, ie. editing when the shape is clicked I get a Runtime Error 13.
Everything works, the form is saved, the email is generated but this nagging error comes up.
Debugging or Ending just quits which is what I want.

I know what is happening fundamentally, Excel is saying "I can't quit because you're editing, pal. Exit the **** cell!" just like when a dialog box is open you can't open another file.

a. Why might it be happening?
b. Can I stop/mitigate/obviate it?

I've tried all manner of error traps and Resume Nexts and turning off error messages and switching on and off Application.Displayalerts... it/s really annoying!

Thanks

Chris
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Try the following

Code:
    Application.DisplayAlerts = False
    Range("A1").Select
    '
    'your code
    '
    Application.Quit
 
Upvote 0
If you are in Edit mode & click a shape, that should automatically take you out of edit mode.
 
Upvote 0
If you are in Edit mode & click a shape, that should automatically take you out of edit mode.

True. And it does on the workbook side, I can see the interface change as the button is clicked but something is keeping it alive for the VBA.

I did the test and I do not have the error. Could you put your macro to review it.

Here you go :)

If I add a Stop just before Application.Quit all works fine. It's the act of quitting while it thinks there is something going on in a cell.

Thanks guys

Code:
Sub Email_Config()
'Mail from Author to Config Team

'Hide alerts for "this file exists," "Are you sure you want to exit?" etc..
Application.DisplayAlerts = False

'Error trap
On Error GoTo Errorcatch

'Empty field catch
If Range("C3") = "" Then MsgBox "Please fill in Applic Type": Range("C3").Select: GoTo endy
If Range("F2") = "" Then MsgBox "Please fill in Issue No.": Range("F2").Select: GoTo endy

'Set mail attributes
Dim oApp, oMail As Object

'Turn off screen updating
Application.ScreenUpdating = False

'Create an Outlook object and new mail message
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(0)

'Break Links to avoid potential Update Links messages
Dim link As Variant, wb As Workbook, origFile As String, newFile As String
  
Set wb = Application.ActiveWorkbook
  
If Not IsEmpty(wb.LinkSources(xlExcelLinks)) Then
    For Each link In wb.LinkSources(xlExcelLinks)
        wb.BreakLink link, xlLinkTypeExcelLinks
    Next link
End If
  
 
'Shows Author mail button and greys out response section
ActiveSheet.Shapes.Range(Array("but_authmail1")).Visible = True
ActiveSheet.Shapes.Range(Array("mask")).Visible = False
  
'Sets variable to current wbook
origFile = wb.FullName
  
'Sets variable to new path
tempfile = Left(origFile, Len(origFile) - 16) & "Received\"
  
'Adds Req No info to file name + path in one big string
newFile = tempfile & Mid(Right(origFile, 16), 1, 11) & " - " & Left(Range("F3"), 4) & "_" & Right(Range("F3"), 4) & Right(origFile, 5)
  
'Saves in Received area
ActiveWorkbook.SaveAs Filename:=newFile

'Sets active wbook to new filename
newFile = ActiveWorkbook.Name

Call testSave

'Message box
MsgBox "Applicability Request Form " & Range("F3") & " has been saved in the Config 'Received' area. When you click OK, Excel will close." & vbCrLf & vbCrLf & "Please send the confirmation email that pops up.", , "You ok with this?"
   
'Creates mail
With oMail
    .to = "xxxxxxxxxxxx"
    .Subject = "Applic Req Form - " & ActiveSheet.Range("F3")
    .body = "Applicability Request Form No. " & Range("F3") & " submitted by " & Range("C7") & " has been created and is in the Received folder - link below:" & vbCrLf & vbCrLf & _
    """\\greenlnk\data\Olympia\" & ActiveWorkbook.Name & """" & vbCrLf & vbCrLf & "Thanks."
    .Display
End With
  
'Turn back on screen updating
Application.ScreenUpdating = True
Application.DisplayAlerts = False

Application.Quit
   
endy:
End

'Error info if caught
Errorcatch:
MsgBox Err.Description

End Sub
 
Last edited:
Upvote 0
No, I do not have an error, I tried your code and I do not have an error. I even omitted this line On Error GoTo Errorcatch.
In all the tests excel quit without problems.
 
Upvote 0

Forum statistics

Threads
1,216,525
Messages
6,131,183
Members
449,630
Latest member
parkjun

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top