1

I have a macro in a book that opens up my separate "vessel book", runs a copy and paste type macro, saves, and then closes the book.

Everything works apart from when it comes to close, the book will prompt the pop-up "would you like to save, yes no etc", even though the macro has save written into it?

Therefore it doesn't actually close - this is really annoying as I would like to schedule it to happen everyday, and if it doesn't close then it won't be able to.

Apparently it is not possible to turn this prompt window off so any help would be great.

Please find my formula below.

Sub AllFiles()

    Application.Run "'G:\Research\Analysts\Elliot Frost\Barge_Tracker_Master.xlsm'!HistoricalData"
    Workbooks("Barge_Tracker_Master.xlsm").Close savechanges:=True

End Sub

'=============================================================

Sub Scheduler()

    '-- RUNS SUB(S) (OR FUNCTIONS) AT TIME SCHEDULED.

    Application.OnTime TimeValue("11:28:00"), "AllFiles"

End Sub
Shai Rado
  • 33,032
  • 6
  • 29
  • 51

2 Answers2

1

Check the answer from this post:

Sub test()
   '[...]
    Application.DisplayAlerts = False
    ThisWorkbook.Save
    ThisWorkbook.Close False
    Application.DisplayAlerts = True
End Sub
Community
  • 1
  • 1
GôTô
  • 7,974
  • 3
  • 32
  • 43
1

Add Application.DisplayAlerts = False, like this :

Sub AllFiles()

With Application
    .Run "'G:\Research\Analysts\Elliot Frost\Barge_Tracker_Master.xlsm'!HistoricalData"
    DoEvents
    .DisplayAlerts = False
End With

Workbooks("Barge_Tracker_Master.xlsm").Close savechanges:=True
Application.DisplayAlerts = True

Scheduler
End Sub

Sub Scheduler()

'-- RUNS SUB(S) (OR FUNCTIONS) AT TIME SCHEDULED.

Application.OnTime TimeValue("11:28:00"), "AllFiles"

End Sub
R3uK
  • 14,417
  • 7
  • 43
  • 77
  • Thanks a lot, works perfectly! Could you please confirm that my application.ontime will run everyday at that time? Thanks a lot – elliot frost Feb 09 '17 at 10:49
  • @elliotfrost : See http://www.cpearson.com/excel/OnTime.aspx, for proper implementation. I've already added the Scheduler at the end of AllFiles to rearm the OnTime after executing! So that should work already! ;) – R3uK Feb 09 '17 at 10:52
  • Thanks a lot, appreciate your help! – elliot frost Feb 09 '17 at 12:20
  • @elliotfrost : If the answers solve your issue, please accept one that helped to close your question and help others that might have the same issue find the answer quicker! – R3uK Feb 13 '17 at 11:36