pastotnikr
New Member
- Joined
- Aug 15, 2014
- Messages
- 1
The code I am presenting is simplified for illustrative purposes but essentially the Workbook_BeforeSave routine cycles through each sheet in my workbook and applies some formatting. This worked in excel 2003 but quit working after converting to excel 2013.
I have a XLSM workbook with 3 sheets (MainSheet, Score1Q, Score2Q)
If I click the disk icon and initiate a save from the excel menu, the code cycles through the sheets and changes focus as expected (confirmed with a MsgBox).
If I initiate the save via code (e.g. a command button on the MainSheet), the code runs (as confirmed by the Msg Boxes) BUT the activesheet does not change (confirmed by the last Msg Box)
Any ideas / help would be appreciated
'** ThisWorkbook code **
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
DoSomething
Me.Worksheets(1).Activate
End Sub
'** MainSheet code **
Private Sub btnTest_Click()
Application.EnableEvents = True
ActiveWorkbook.Save
End Sub
'** code in module modMain **
Public Sub DoSomething()
Application.ScreenUpdating = False
Call GoToSheet("Score1Q")
Call GoToSheet("MainSheet")
Call GoToSheet("Score2Q")
Application.ScreenUpdating = True
End Sub
Public Sub GoToSheet(strSheet As String)
ThisWorkbook.Sheets(strSheet).Activate
MsgBox "Activated Sheet: " & strSheet
ThisWorkbook.Sheets(strSheet).Select
MsgBox "Selected Sheet: " & strSheet
MsgBox ThisWorkbook.Name & vbCrLf & _
"Activated & Selected Sheet: " & strSheet & vbCrLf & "ActiveSheet: " & ActiveSheet.Name
End Sub
I have a XLSM workbook with 3 sheets (MainSheet, Score1Q, Score2Q)
If I click the disk icon and initiate a save from the excel menu, the code cycles through the sheets and changes focus as expected (confirmed with a MsgBox).
If I initiate the save via code (e.g. a command button on the MainSheet), the code runs (as confirmed by the Msg Boxes) BUT the activesheet does not change (confirmed by the last Msg Box)
Any ideas / help would be appreciated
'** ThisWorkbook code **
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
DoSomething
Me.Worksheets(1).Activate
End Sub
'** MainSheet code **
Private Sub btnTest_Click()
Application.EnableEvents = True
ActiveWorkbook.Save
End Sub
'** code in module modMain **
Public Sub DoSomething()
Application.ScreenUpdating = False
Call GoToSheet("Score1Q")
Call GoToSheet("MainSheet")
Call GoToSheet("Score2Q")
Application.ScreenUpdating = True
End Sub
Public Sub GoToSheet(strSheet As String)
ThisWorkbook.Sheets(strSheet).Activate
MsgBox "Activated Sheet: " & strSheet
ThisWorkbook.Sheets(strSheet).Select
MsgBox "Selected Sheet: " & strSheet
MsgBox ThisWorkbook.Name & vbCrLf & _
"Activated & Selected Sheet: " & strSheet & vbCrLf & "ActiveSheet: " & ActiveSheet.Name
End Sub