VBA & Macro Problems

Fix Excel 365 Macros Switching Focus to Another Workbook

Jason MillerJason Miller Nov 13, 2026 869 views

Question details

Identify why Excel 365 macros switch focus to another workbook and prevent unintended workbook activation.

Fix Excel 365 Macros Switching Focus to Another Workbook
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.
Before you start

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.

Solution 1Recommended

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.

1
Create test workbooks

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.

2
Inspect the macro

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.

3
Specify the target

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.

4
Check activation events

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 New Workbooks and Qualify VBA References
Choose the target explicitly: ActiveWorkbook can change during a macro. If the macro should work on the workbook active when it starts, store that workbook in a variable before any action that might change focus.
Free Microsoft Office alternative

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.

Open and edit common Excel workbook formats, including XLSXUse a familiar spreadsheet interface for everyday workbook tasksWork with multiple spreadsheets in a lightweight office suiteTry a free alternative while troubleshooting Excel workbook behavior
microsoft office alternative - wps office

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.