Saving file with "." in filename

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,924
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
My workbook is called abc.xlsm

I run the following code and it's fine, ie it saves it as abc.xlsm

Code:
ThisWorkbook.SaveAs Filename:=Left(String:=ThisWorkbook.FullName, _
                                                       Length:=Len(ThisWorkbook.FullName) - 5)

If I now save my workbook, close it, change its name in Windows Explorer to abc 1.2.xlsm, then open and run the above code, the file is no longer saved as an Excel file,

ie in Windows Explorer, I see a file called abc 1.2 (without the .xlsm extension), so it doesn't know it's an Excel file, meaning double clicking doesn't automatically open it.

I suspect the reason for this odd behaviour is that abc 1.2.xlsm contains a "." in the filename.

Why does VBA behave in this way and going forwards, is it NOT a good idea to save filenames with a "."?

Thanks
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
It's a better idea to specify the FileFormat parameter in all SaveAs operations, otherwise you may run into many unexpected problems.
 
Upvote 0
It's a better idea to specify the FileFormat parameter in all SaveAs operations, otherwise you may run into many unexpected problems.

Thanks but adding this didn't help:

Code:
FileFormat:=52

it still saved it without the file extension.
 
Upvote 0
Why aren't you including the extension in the file name when you save it?
 
Upvote 0
Why aren't you including the extension in the file name when you save it?

If the filename was already .xlsm, this code saved it as .xlsm as well , provided the filename DIDN'T have a "." in it.

Code:
ThisWorkbook.SaveAs Filename:=Left(String:=ThisWorkbook.FullName, _
                                                       Length:=Len(ThisWorkbook.FullName) - 5)

ie if the filename was myfile.xlsm, then the above code saved it as myfile.xlsm.

However, if the filename was myfile_v1.1.xlsm, using the above code didn't automatically add the .xlsm. It saves it as myfile_v1.1
 
Last edited:
Upvote 0
That doesn't really explain why you aren't including the extension in the file name when you save it.
 
Upvote 0
Because when I first did it, it automatically included it, so I didn't think you had to.
 
Upvote 0
Also. I would say it's really not a good idea to have additional "." in the file name in addition to the separator before the file extension
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,329
Members
452,635
Latest member
laura12345

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