VBA & Macro Problems

How to Fix Excel Macros Opening the Original Workbook Instead of a Renamed Copy

Algirdas JasaitisAlgirdas Jasaitis Nov 2, 2026 869 views

Question details

Excel VBA macros inadvertently open or modify the original workbook after the file has been renamed or copied.

How to Fix Excel Macros Opening the Original Workbook Instead of a Renamed Copy
Product
Microsoft Excel
Device & OS
not provided
Scenario
Running VBA macros in a copied or renamed workbook to process daily data with variable row counts.
Observed behavior
The macro continues to target or open the original workbook instead of executing within the newly renamed copy.
Before you start

Before modifying your VBA code, create a safe backup of your current workbook and ensure the Developer tab is enabled in your ribbon so you can access the Visual Basic Editor.

Solution 1Recommended

Fix Hard-Coded Workbook Names and Object References

Update your VBA code to reference the workbook running the code rather than a hard-coded file name.

Macros often fail in copied workbooks because the code explicitly calls out the original file's name. Replacing these with dynamic references ensures the macro always applies to the file it is running from.

1
Open the Visual Basic Editor

Press ALT + F11 to open the VBA editor and double-click the module containing your macro in the Project Explorer.

2
Find Hard-Coded References

Press CTRL + F to search for references like Workbooks("OriginalName.xlsx") or similar hard-coded file names in your code.

3
Replace with ThisWorkbook

Change the hard-coded workbook references to ThisWorkbook. This tells VBA to execute the code on the file where the macro is stored, regardless of its current file name.

4
Remove Select and ActiveCell

Replace .Select and ActiveCell methods with direct object references, such as ThisWorkbook.Sheets("Sheet1").Range("A1"), to prevent the macro from jumping to unintended open workbooks.

Fix Hard-Coded Workbook Names and Object References
Handling Dynamic Row Counts: Using direct object references allows your macro to easily calculate variable daily data sizes without relying on selected ranges.
Seamless Excel Macro Compatibility

Run and Edit VBA Macros Smoothly with WPS Spreadsheet

WPS Office provides excellent support for VBA macros, allowing you to run, edit, and debug your existing Excel scripts without modification. Enjoy a lightweight, fast, and highly compatible spreadsheet environment.

  1. 1. Open Your Macro Workbook in WPS: Launch WPS Spreadsheet and open your .xlsm or .xlsb file containing the macros.
  2. 2. Enable Macros: Click 'Enable Macros' in the security warning prompt that appears at the top of your workspace.
  3. 3. Access the VBA Editor: Navigate to the Developer tab and click on the 'VBA Editor' icon to review or modify your macro code.
Native support for VBA and macro execution without rewriting codeFully compatible with Microsoft Excel .xlsm and .xlsb formatsFamiliar Developer tab and Visual Basic Editor interfaceLightweight application that handles variable row counts efficiently
microsoft office alternative - wps office

Frequently Asked Questions

Why does my macro work on the original file but not the renamed copy?

This happens because the VBA code explicitly names the original file (e.g., Workbooks("Original.xlsx")). When you run it from the copy, VBA looks for the exact name of the original file instead of applying the actions to the copy.

What is the difference between ActiveWorkbook and ThisWorkbook in VBA?

ActiveWorkbook refers to the file currently in focus on your screen, which can change unexpectedly if another file opens. ThisWorkbook specifically refers to the file where the VBA code itself is stored, making it much more reliable for referencing.

How do I make a macro automatically handle different numbers of rows each day?

Instead of hard-coding row numbers or using .Select, use dynamic range calculations in your VBA code. For example, Cells(Rows.Count, 1).End(xlUp).Row will find the last used row dynamically.

Where is the Personal.xlsb file stored on my computer?

In Windows, the Personal Macro Workbook is typically stored in the XLSTART folder located at C:\Users\[Username]\AppData\Roaming\Microsoft\Excel\XLSTART. It opens invisibly in the background whenever you start the application.