Save file with active sheet name to fixed path

2Took

Board Regular
Joined
Jun 13, 2022
Messages
203
Office Version
  1. 365
Platform
  1. Windows
So, this code works on ActiveSheet, names it and then saves it to a fixed path.

Problem is it omits file extension. Need it to use the same file extension as original file has.

VBA Code:
Sub MySaveTabName()
With CreateObject("Scripting.FileSystemObject")
strExt = "." & .GetExtensionName(ActiveWorkbook.FullName)
ActiveSheet.Name = "ABC - " & Format(Now(), "MM.dd.yy")
MyName = ActiveSheet.Name
End With
Const csPath As String = "C:\Test\"
ActiveWorkbook.SaveAs Filename:=csPath & MyName & strExt
End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
This code works perfectly for me. I started with a .xlsm file and it renamed the active sheet to be "ABC - 08.05.22" and saved the file as "ABC - 08.05.22.xlsm" . It does not omit the file extension.

Also it saves the entire file, not just the active sheet, but you didn't mention that as a problem.
 
Upvote 0
This code works perfectly for me. I started with a .xlsm file and it renamed the active sheet to be "ABC - 08.05.22" and saved the file as "ABC - 08.05.22.xlsm" . It does not omit the file extension.

Also it saves the entire file, not just the active sheet, but you didn't mention that as a problem.
Thanks, I already figured out that the problem stems from the fact that the file I'm trying to save simply does not have an extension to begin with :)

It is an exported report from the system, so solution is to have last line as:

VBA Code:
ActiveWorkbook.SaveAs Filename:=csPath & MyName & ".xlsx"
 
Upvote 0
Solution
If you are saving ActiveWorkbook how can it not have an extension?
 
Upvote 0

Forum statistics

Threads
1,215,480
Messages
6,125,050
Members
449,206
Latest member
Healthydogs

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