Worksheet Tab Being Renamed During Save Process & Unable to open newly created .xlsx file (invalid file extension?)

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,616
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Please consider this code ...

Rich (BB code):
       With wb_classcsv
            .Sheets.Add(After:=.Sheets(.Sheets.Count)).Name = "Stats"
            Set ws_stats = .Worksheets("Stats")
            With ws_stats
                .Range("A3") = "Date:  "
                .Range("B3") = Format(usr_date, "dd-mmm-yy")
                .Range("C3") = Format(usr_date, "00000")
                .Range("A4") = "Created:  "
                .Range("B4") = Format(Now, "dd-mmm-yy")
                .Range("C4") = Format(Now, "h:mm:ss am/pm")
                .Cells.EntireColumn.AutoFit
            End With
            fname = Format(usr_date, "mmm-dd (ddd)") & " Data.xlsx"
            stname = "U:\PWS\Parks\Parks Operations\Sports\WATSOP19\DATA\" & fname
            Application.DisplayAlerts = False
            .SaveAs Filename:=stname
            Application.DisplayAlerts = True
        End With

'wb_classcsv' is opened as a .csv file.
WIth the lines in blue, I create a new worksheet in workbook 'wb_classcsv' and name it 'stats' and set ws_stats to to it.
The red line saves the file with a name of (example) "Jun-24 (Mon).xlsx".

I am running into two problems...

1) The tab I named 'stats' is changing to 'Jun-24 (Mon)' with the saving of this file for some reason I cannot explain. This will cause problems for me down the road, I cannot allow this tab to be renamed to anything other than 'stats'

2) I cannot open this newly created file. I get the error "Excel cannot open the file 'Jun-24 (Mon).xlsx' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file."

Please, can anyone help?
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Please consider this code ...

Rich (BB code):
       With wb_classcsv
            .Sheets.Add(After:=.Sheets(.Sheets.Count)).Name = "Stats"
            Set ws_stats = .Worksheets("Stats")
            With ws_stats
                .Range("A3") = "Date:  "
                .Range("B3") = Format(usr_date, "dd-mmm-yy")
                .Range("C3") = Format(usr_date, "00000")
                .Range("A4") = "Created:  "
                .Range("B4") = Format(Now, "dd-mmm-yy")
                .Range("C4") = Format(Now, "h:mm:ss am/pm")
                .Cells.EntireColumn.AutoFit
            End With
            fname = Format(usr_date, "mmm-dd (ddd)") & " Data.xlsx"
            stname = "U:\PWS\Parks\Parks Operations\Sports\WATSOP19\DATA\" & fname
            Application.DisplayAlerts = False
            .SaveAs Filename:=stname
            Application.DisplayAlerts = True
        End With

Do you forget "Data" for name of file? You check-in it so!
Filename can 'Jun-24 (Mon) Data.xlsx'
 
Last edited:
Upvote 0
You need to specify the fileformat argument when saving as a different format.
 
Upvote 0
Do you forget "Data" for name of file? You check-in it so!
Filename can 'Jun-24 (Mon) Data.xlsx'

Thank you sadboy, that was an error in my post. I failed to include the 'data' in my example, but thank you for pointing out the need to be accurate when posting!
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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