Excel 2013 Workbook_BeforeSave code does not change activesheet

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
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,215,537
Messages
6,125,398
Members
449,222
Latest member
taner zz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top