Hi Steve,
You may be able to do what you want by using a global variable to indicate whether a sheet was activated by Macro or Manually.
Try the following code in the ThisWorkbook Module:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If bSheetActivatedByMacro = True Then
MsgBox "Workbook_SheetActivate() triggered BY MACRO on '" & Sh.Name & "'" & vbCrLf & _
"No Warning message needed."
Else
MsgBox "Workbook_SheetActivate() triggered MANUALLY on '" & Sh.Name & "'" & vbCrLf & _
"DANGER WILL ROBINSON."
End If
End Sub
Try the following code in an ordinary module:
Option Explicit
Public bSheetActivatedByMacro As Boolean
Sub CommandButton1_Click()
bSheetActivatedByMacro = True
Sheets("Sheet2").Select
'''''
'your other code here
'''''
bSheetActivatedByMacro = False
End Sub
Code tested and working in Excel 2003. When a sheet is selected manually, the WARNING PATH is activated. When a sheet is selected by Macro, the NO WARNING path is activated.
Lewis
Bookmarks