Worksheet changing names to workbook name

Dummy Excel

Well-known Member
Joined
Sep 21, 2005
Messages
1,004
Office Version
  1. 2019
  2. 2010
  3. 2007
Platform
  1. Windows
Hi All,
I have created a macro to format some raw data from our system. When we receive the data from our system it always has a new file & worksheet name. So to get around this in the beginning i use the below code and then call the workbook/worksheet when required;
Code:
    j = ActiveWorkbook.Name
    K = ActiveSheet.Name

At the end of the report I rename my worksheet (k) to something more meaningful using the code below;
Code:
Sheets(K).Name = "Dogs"

This all works great until I go and save my formatted report. Please see code below to save the report, although just before it saves the report, it changes the worksheet name from Dogs to Dogs OOS 170611
Code:
    filedate = InputBox("Enter today's date as ddmmyy", , "010111")
    Filename = "Dogs OOS " & filedate
    ActiveWorkbook.SaveAs Filename:="C:\Pets OOS Reports - Dogs\" & Filename & ".xls"

Any thoughts/help would be greatly appreciated
regards
Sam
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Try this:
Code:
'filedate = Format(InputBox("Enter today's date as ddmmyy", , Date), "ddmmyy")
    filedate = Format(Date, "ddmmyy")
    myFilename = "Dogs OOS " & filedate
    ActiveWorkbook.SaveAs Filename:="C:\Pets OOS Reports - Dogs\" & myFilename & ".xls"

"Filename" is a reserved/keyword in VBA.
 
Upvote 0
So to restate the issue:
A:You are not getting any error messaging
B:On the SaveAs though, it changes the worksheet name to the workbook name.
The posted code would not cause B: to occur.

Is there anything in a Sub Workbook_BeforeSave event?
I might put a break (Select the code line and F9) on the SaveAs, and then F8 from there and see if it takes you through any "Sheets(K).Name = " code.
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,866
Members
452,948
Latest member
UsmanAli786

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