Fix Excel 365 Macros Switching Focus to Another Workbook
Question details
Identify why Excel 365 macros switch focus to another workbook and prevent unintended workbook activation.

- Product
- Microsoft Excel 365
- Device & OS
- not provided
- Scenario
- Macros stored in Personal.xlsb are run while multiple workbooks are open.
- Observed behavior
- Focus returns to the first workbook in which a macro was run during the session. Unexpected navigation also occurs in another Microsoft 365 application.
Note which workbook is active before and after running the macro, and whether the same behavior occurs in other Office applications. If you use a managed work laptop, check with your IT administrator before changing add-ins, startup settings, or the Office installation.
Test New Workbooks and Qualify VBA References
Use this test to determine whether the focus change is specific to a workbook or caused by macro code.
In Excel, select File > New twice to create two blank workbooks. Run a simple test macro in each and check whether focus returns to the first workbook.
Press Alt+F11 to open the Visual Basic Editor. In the Project pane, open Personal.xlsb and review the macro for unqualified references such as Range("A1"), Cells, and ActiveSheet.
In the macro, assign the intended workbook and worksheet to variables, then qualify ranges through those variables, such as targetSheet.Range("A1"). In a macro stored in Personal.xlsb, ThisWorkbook refers to Personal.xlsb, not necessarily the workbook being edited.
In the Visual Basic Editor, inspect ThisWorkbook, worksheet modules, and any application-event code for Activate or Select commands. Remove or revise commands that unintentionally switch workbooks, then rerun the test.

Test Excel Safe Mode and Disable Add-ins
On Windows, use Safe Mode to check whether an add-in or startup component contributes to the focus change.
Check Windows Startup and Repair Microsoft 365
Consider these Windows checks if the behavior persists or also affects other Microsoft 365 applications.
Work with Excel Files in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and support for Microsoft Office formats, making it easier to move everyday workbook tasks to another suite. It does not repair Excel or guarantee that VBA macros will work unchanged.

Frequently Asked Questions
Why does a macro in Personal.xlsb affect the wrong workbook?
Unqualified references such as Range("A1") depend on the active context, which can change during execution. In the Visual Basic Editor, assign the intended workbook and worksheet to variables and qualify each range through them.
Does ThisWorkbook refer to the workbook I am editing?
Not when the code is stored in Personal.xlsb: ThisWorkbook refers to Personal.xlsb. If the intended target is the active workbook at the start, store ActiveWorkbook in a variable before focus can change.
How do I check whether an add-in is causing the switch?
On Windows, start Excel with Windows+R and excel /safe, then repeat a simple test. If the issue stops, use File > Options > Add-ins to disable COM and Excel add-ins and re-enable them one at a time.
Can workbook events activate another file?
Yes. Workbook, worksheet, or application event procedures can run activation commands. Press Alt+F11 and inspect event code for Activate and Select statements that target another workbook.
What if Outlook also changes focus unexpectedly?
A problem in more than one Office application may point beyond a single workbook. With IT approval, try a Windows clean boot and use Microsoft 365's Modify option in Windows Settings to run Quick Repair or Online Repair.




