Fix Excel VBA Not Renaming a Newly Added Worksheet
Question details
The user needs to rename a worksheet immediately after creating it with Excel VBA.

- Product
- Microsoft Excel VBA
- Device & OS
- not provided
- Scenario
- A VBA macro adds a worksheet and should assign a specified name to its tab.
- Observed behavior
- The worksheet is created, but its tab does not receive the expected name, including when a literal string or a variable is used.
Check the target workbook and the intended worksheet name before running the macro. Worksheet names must be unique within the workbook, contain no more than 31 characters, and cannot include these characters: \ / ? * [ ] :.
Store the New Worksheet Reference Before Renaming It
Use an explicit worksheet reference to ensure the name is assigned to the sheet the macro just created.
ThisWorkbook refers to the workbook containing the macro, which may differ from the active workbook. Use the intended workbook reference if the new sheet belongs elsewhere.
This approach may not resolve the issue by itself if the same code already fails in your workbook. Use the test and troubleshooting steps below to isolate the cause.
In Excel, open Developer > Visual Basic, then open the module containing your macro.
Use an object variable when adding the sheet, for example: Dim ws As Worksheet Dim destSht As String destSht = "Hello World" Set ws = ThisWorkbook.Worksheets.Add ws.Name = destSht
Run the macro from the VBA editor and check the new tab in the workbook containing the code. If an error appears, select Debug to inspect the highlighted line and the value of destSht.
If adding or renaming is blocked, check Review > Protect Workbook for workbook structure protection and remove it if you have permission.

Test the Macro in a New Workbook and Repair the Original File
Use a clean workbook to determine whether the problem is specific to the original file.
Check Excel Add-ins and Repair Office
Use this approach if the same macro also fails in a new workbook. The Safe Mode and repair steps below apply to Windows.
Work With Excel Spreadsheets in WPS Office
WPS Office is a free, lightweight alternative for everyday spreadsheet work, with a familiar interface and support for common Excel formats to help you move between office suites. It does not repair Excel or guarantee compatibility with every VBA macro.

Frequently Asked Questions
Why does my macro create a sheet but leave its default name?
The rename line may be targeting a different sheet, not executing, or encountering an error. Store the result of Worksheets.Add in a Worksheet variable, set its Name, and use Debug in the VBA editor to inspect any error.
Does ThisWorkbook mean the workbook I currently have open?
ThisWorkbook is the workbook containing the VBA code. It may not be the active workbook. Use a reference to the intended workbook when calling Worksheets.Add.
What makes an Excel worksheet name invalid?
A worksheet name must be unique within the workbook, be no more than 31 characters, and cannot contain \ / ? * [ ] :. Check the value of your name variable before assigning it.
How can I tell whether an add-in is causing the problem?
On Windows, start Excel with excel /safe from the Windows+R dialog and run the macro. If it works in Safe Mode, check File > Options > Add-ins and disable add-ins to isolate the conflict.




