I'm not sure if this will help but this is what I use to shut down Excel.
Maybe it can be "adjusted" to suit what you want.
I've also tried many times to implement/build a "general" error routine but that has escaped me because as you say... one problem is where to put it!
I can only think that you may have to put code into the before save event that calls code in another open workbook or an add in.
An Add In may be a good choice actually because it gets loaded when you open excel and can be made available to all projects.
Sub subShutDownExcel()
' Save all workbooks and quit.
Dim wblWorkBook As Workbook
Dim slWorkBooks() As String
Dim lngErrNumber As Long
Dim blnlDone As Boolean
Dim lnglWorkBooksOpen As Long
Dim lnglClosed As Long
lnglWorkBooksOpen = Workbooks.Count
lnglClosed = 0
blnlDone = False
With Application
Do
For Each wblWorkBook In Workbooks
On Error Resume Next
Application.DisplayAlerts = False
wblWorkBook.Save
Application.DisplayAlerts = True
wblWorkBook.Close
lngErrNumber = Err.Number
On Error GoTo 0
Select Case lngErrNumber
Case 0
lnglClosed = lnglClosed + 1
End Select
Next wblWorkBook
If lnglClosed = lnglWorkBooksOpen Then
Exit Do
ElseIf lnglClosed > 10 Then
' Sanity check.
Exit Do
End If
Loop
.Quit
End With
' ***********************************************************************
End Sub
-----Original Message-----
From: Torstein Johnsen sejohnse@yahoo.no [ExcelVBA] <ExcelVBA@yahoogroups.com>
To: Yahoogroups <excelvba@yahoogroups.com>
Sent: Thu, Aug 31, 2017 9:19 am
Subject: [ExcelVBA] BeforeSave - event - working on all files
I know the beforeSave-event that can be added to a workbook and executes before the user saves that workbook.
I want to make a general beforeSave-event that executes before the user saves any workbook.
I suppose I may have missed something about Application events but I can't figure out where to put such an event.
My goal is to make a log of each file saved.
r egards Torstein
Tidak ada komentar:
Posting Komentar