+ Reply to Thread
Results 1 to 5 of 5

Cannot Quit at this time Error

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-24-2006
    Location
    Sevenoaks, Kent
    MS-Off Ver
    Office 365 ProPlus
    Posts
    459

    Cannot Quit at this time Error

    Good afternoon,

    I hoping someone can help me because i'm completely baffled. Every morning at 8am have an excel file that opens up via a task scheduler command, after 56 minutes @ 8:56 excel trys to close of its own accord and I get this message from excel saying "Cannot Quit at this time" from a "Microsoft Visual Basic for Applications" pop up box, This stops everything from running and i have to clear the message before it will continue, once i clear the message it will run fine for the rest of the day until tomorrow at 8:56am. I can guarantee there is nothing in my vba code that attempts to close down my excel at this time. I will add all of my vba below.

    If anyone could help i would be really grateful.

    Module 1

    Sub Close_Workbook()
    Application.DisplayAlerts = False
    Application.Quit
    End Sub
    Module 2

    Sub Refresh()
    Application.OnTime Now + TimeValue("00:00:30"), "Refresh"
    If Worksheets("Data").Range("T2").Value = "" Then Exit Sub
    ActiveWorkbook.Connections("Query from csolve5").Refresh
    ActiveWorkbook.Connections("Query from csolve3").Refresh
    ActiveWorkbook.Connections("Connection").Refresh
    ''Application.Run "'Card Report v5.xlsm'!Refresh"
       
    Sheets("Data").Select
    Range("Table_Query_from_csolve[[#Headers],[DebtorID]]").Select
        Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
        Sheets("All Cards").Select
       ' Select the range of cells on the active worksheet.
       With Sheets("All Cards").Range("A1:I50")
       ActiveSheet.Range("A1:I50").Select
       End With
       ' Show the envelope on the ActiveWorkbook.
       ActiveWorkbook.EnvelopeVisible = True
       
       ' Set the optional introduction field thats adds
       ' some header text to the email body. It also sets
       ' the To and Subject lines. Finally the message
       ' is sent.
       With ActiveSheet.MailEnvelope
          '.Introduction = ""
          .Item.To = "[email protected]"
          '.Item.CC = "[email protected]"
          .Item.Subject = [Z1] & " " & Format(Date, "dd/mm/yy")
          .Item.Send
          Application.OnTime Now + TimeValue("00:00:30"), "Refresh"
          End With
          Application.OnTime Now + TimeValue("00:00:30"), "Refresh"
    End Sub
    This Workbook

    Private Sub Workbook_Open()
    
    
      Application.OnTime Now + TimeValue("00:00:30"), "Refresh"
      Application.OnTime TimeValue("20:15:00"), "Close_Workbook"
      
      'Cancel any previous scheduled run
        On Error Resume Next
        Application.OnTime TimeValue("20:05:00"), "Refresh", , False
        Application.OnTime TimeValue("20:15:00"), "Close_Workbook", , False
        On Error GoTo 0
    
    'Add scheduled run again
    Application.OnTime TimeValue("20:15:00"), "Close_Workbook"
        
         Set objmessage = CreateObject("CDO.Message")
          Set objconfig = CreateObject("CDO.Configuration")
           
          Recipients = "[email protected]"                                                               'Type in your own recipient'
          ''CC = ""                                                                                                      'Self Explanatory'
          ''BCC = ""                                                                                                     'Self Explanatory'
          From = "[email protected]"                                                                                          'No Spaces'
          Subject = "Card Report is Active - " & Format(Now(), "hh:mm")                                            'This can whatever the message needs to be
          HTMLBody = "*****File Opended Successfully*****"                                                                                    'This can whatever the message needs to be'"
          With objconfig.Fields
                      .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2                              'Do not change'
                      .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "SMTP.local.1stcreditltd.com" 'This needs to the name of your compnay exchange'
                      .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30                 'Do not change'
                      .Update
          End With
          With objmessage
                      .Configuration = objconfig
                      .To = Recipients
                      .CC = CC
                      .BCC = BCC
                      .From = From
                      .Subject = Subject
                      .HTMLBody = HTMLBody
                      .Send
          End With
          'Destroy Objects
          'Set objmessage = Nothing
          'Set objconfig = Nothing
      
    ' VBMail Ends Here
    
        End Sub
    No other VBA is present in the sheet




    Thanks in advance DJ
    Last edited by djfatboyfats; 07-21-2016 at 07:23 AM.

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Cannot Quit at this time Error

    Hi,

    Why does your Refresh routine reschedule itself 3 times? It would seem to me that that will create an enormous schedule of refreshes quite quickly, and that probably conflicts with your scheduled Close routine, which may be trying to close while a connection is refreshing.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Cannot Quit at this time Error

    Private Sub Workbook_Open()
    
    
      Application.OnTime Now + TimeValue("00:00:30"), "Refresh"
      Application.OnTime TimeValue("20:15:00"), "Close_Workbook"
      
      'Cancel any previous scheduled run
        On Error Resume Next
        Application.OnTime TimeValue("20:05:00"), "Refresh", , False
        Application.OnTime TimeValue("20:15:00"), "Close_Workbook", , False
        On Error GoTo 0
    
    'Add scheduled run again
    Application.OnTime TimeValue("20:15:00"), "Close_Workbook"

    This is confusing. Why schedule OnTime events; cancel them; then reschedule them?

    Also, this....
    Application.OnTime TimeValue("20:05:00"), "Refresh", , False
    Does not cancel this...
    Application.OnTime Now + TimeValue("00:00:30"), "Refresh"
    ...because the Now command makes the time values different between the two, and the On Error Resume Next hides the error.

    You could store the Now + TimeValue("00:00:30") value as a public variable then use that variable to cancel the event when necessary.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Forum Contributor
    Join Date
    08-24-2006
    Location
    Sevenoaks, Kent
    MS-Off Ver
    Office 365 ProPlus
    Posts
    459

    Re: Cannot Quit at this time Error

    The reason I cancelled events then rescheduled them is because i found if the workbook closed down in the day then reopened it would perform the same task twice or as many times the sheet opened and closed, which meant people was receiving multiple emails for the same data. I have made some code adjustments based on both your answers and im hoping the changes will resolve the problem. i will let you know tomorrow morning when it runs.

    Thanks

    DJ

  5. #5
    Forum Contributor
    Join Date
    08-24-2006
    Location
    Sevenoaks, Kent
    MS-Off Ver
    Office 365 ProPlus
    Posts
    459

    Re: Cannot Quit at this time Error

    First signs look promising. Thanks for your help guys.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Application.Quit Run-Time error 424???
    By biznez in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-14-2016, 04:07 PM
  2. Cannot Publish Excel Pivot Chart - Run Time Error
    By crisb184 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-11-2013, 07:04 AM
  3. run-time error ;2147023179 (800706b5) time automation error interface unknown
    By karthik72 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-02-2012, 09:31 AM
  4. [SOLVED] Truly quit Excel using Application.Quit doesn't work
    By bta in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-29-2012, 04:44 AM
  5. Quit on Error
    By dmartinez in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-28-2011, 01:27 PM
  6. quit on error
    By Ronbo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-15-2006, 05:40 PM
  7. Replies: 3
    Last Post: 08-01-2005, 03:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1