
Originally Posted by
oam
GTO;
There are both version loaded on all the computers! This was a directive from upper management and the R&D team made their own version of Excel 2007 & 2010 so it would load both on each machine. They disabled the macros in Excel 2010 with the idea macros contain virus but we use them make it our process more user friendly, what a pain!
Yeh, tech bureau guys are great. I "get it" though. What little bits of code I've written to help my guys/gals get something or other done easier/quicker/more accurately, at least in Excel, has probably had more code in it to prevent the user from doing stuff they shouldn't ("You mean deleting the cells/rows/columns is somehow different than erasing?").

Originally Posted by
oam
I guess I did not think this through, you are right, how would the macro run if macros are disabled in 2010?...
That was Aflatoon's comment, not mine. I think Sam's idea is neat, though I like using BeforeSave better than BeforeClose. Here's something not tested well, and it will not work for a SaveAs as currently written. Those points mentioned, see if it is something to start with if you like.
In the ThisWorkbook Module:
Option Explicit
Private bInProcess As Boolean
Private bClosing As Boolean
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim intResponse As Long
'Stop '<--- Un-REM Stop(s) to step through
Application.DisplayAlerts = False
If Not bClosing Then
If Not ThisWorkbook.Saved Then
intResponse = MsgBox("Do you want to save the changes you made to '" & _
Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - (Len(ThisWorkbook.Name) - InStrRev(ThisWorkbook.Name, ".")) - 1) & "'?", _
vbExclamation Or vbYesNoCancel Or vbDefaultButton1, _
"My Custom Project")
Select Case intResponse
Case vbYes
bClosing = True
'// See procedure. We don't need to execute the save here, and in //
'// fact, due to a weird glitch in Excel (least 2000), this is //
'// better. //
Call Workbook_BeforeSave(False, False)
'//This is required, as even though the file saved while in //
'// BeforeSave, changes occurred post save. //
ThisWorkbook.Saved = True
Case vbNo
bClosing = True
'// User doesn't want to save changes, so just mark file saved. //
ThisWorkbook.Saved = True
Case vbCancel
'// User cancelled closing, and least in Excel 2000, I found it //
'// necessary to reactivate stuff if I wanted the focus returned. //
ThisWorkbook.Activate
bClosing = False
Cancel = True
Application.DisplayAlerts = True
ActiveCell.Activate
Exit Sub
End Select
End If
End If
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim wksCurrentActiveSheet As Worksheet
Dim wksWorksheet As Worksheet
'Stop
If SaveAsUI Then
Cancel = True
MsgBox "Not enough code to handle a SaveAs...", vbInformation, vbNullString
Exit Sub
End If
If Not (bInProcess And Not Cancel) Then
bInProcess = True
Set wksCurrentActiveSheet = ActiveSheet
shtMacWarn.Visible = xlSheetVisible
For Each wksWorksheet In ThisWorkbook.Worksheets
If Not wksWorksheet.CodeName = "shtMacWarn" Then
wksWorksheet.Visible = xlSheetVeryHidden
End If
Next
Cancel = True
DoEvents
ThisWorkbook.Save
If bClosing = True Then
Exit Sub
End If
For Each wksWorksheet In ThisWorkbook.Worksheets
wksWorksheet.Visible = xlSheetVisible
Next
shtMacWarn.Visible = xlSheetVeryHidden
If Not (ActiveSheet.Name = wksCurrentActiveSheet.Name) _
And (wksCurrentActiveSheet.Visible = xlSheetVisible) Then
wksCurrentActiveSheet.Activate
End If
ThisWorkbook.Saved = True
bInProcess = False
End If
End Sub
Private Sub Workbook_Open()
Dim wksWorksheet As Worksheet
'Stop
For Each wksWorksheet In ThisWorkbook.Worksheets
wksWorksheet.Visible = xlSheetVisible
Next
shtMacWarn.Visible = xlSheetVeryHidden
ThisWorkbook.Saved = True
End Sub
Mark