Needed help trying to SAVE AS current filename

jojo52479

New Member
Joined
Mar 2, 2017
Messages
24
Hello, im trying to figure out a way to SAVE AS in my current program but when I do, I always get filename as my SAVE AS but I want to SAVE AS my current file name. Any help would be appreciated.

If WorksheetFunction.CountA(Range("J10:J33")) > 0 Then
ChDir "C:\Users\Joseph\Desktop\Food Maxx Test\401"
ActiveWorkbook.SaveAs Filename:= _
"C:\Users\Joseph\Desktop\Food Maxx Test\401\FileName.xls", FileFormat:=xlExcel8, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
End If
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I ran your code and it worked fine with the exception that I was asked if i wanted to replace the existing file. I adjusted this like so to avoid this.

Code:
Sub Testing()


Application.DisplayAlerts = False
If WorksheetFunction.CountA(Range("J10:J33")) > 0 Then
ChDir "C:\Users\DeathDealer187\Desktop\"
ActiveWorkbook.SaveAs Filename:= _
"C:\Users\DeathDealer187\Desktop\Test.xlsx", FileFormat:=xlExcel8, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
End If
Application.DisplayAlerts = True
End Sub
 
Upvote 0
If you just want to save the ActiveWorkbook with all the changes you have made, do this:

Code:
ActiveWorkbook.Save

If you want to close the ActiveWorkbook and save all the changes you have made, do this:

Code:
ActiveWrkbook.Close SaveChanges:=True

If you want to save the ActiveWorkbook to a different directory, do this:

Code:
Dim wb_name as String

wb_name = ActiveWorkbook.Name

[COLOR=#333333]If WorksheetFunction.CountA(Range("J10:J33")) > 0 Then[/COLOR]
[COLOR=#333333]'ChDir "C:\Users\Joseph\Desktop\Food Maxx Test\401"[/COLOR]
[COLOR=#333333]ActiveWorkbook.SaveAs Filename:= _[/COLOR]
[COLOR=#333333]"C:\Users\Joseph\Desktop\Food Maxx Test\401\" & wb_name & ".xls", FileFormat:=xlExcel8, _[/COLOR]
[COLOR=#333333]Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _[/COLOR]
[COLOR=#333333]CreateBackup:=False[/COLOR]

You can comment out the ChDir line because you don't need it. The file path already specifies where to save the file.
 
Last edited:
Upvote 0
Thank you both. Great information. YKY, I have a question for your code. On the save the activworksheet program, it works perfect. The only thing im seeing is when I save it, it save perfect. But when I save again, it doesnt prompt me to replace. It just add another .XLS to the end of the original .XLS. So I get "test.xls.xls and if I save it again I get,"test.xls.xls.xls. You get the picture. How would you fix that?
 
Upvote 0
Try editing this line

Code:
[COLOR=#333333]"C:\Users\Joseph\Desktop\Food Maxx Test\401\" & wb_name & ".xls", FileFormat:=xlExcel8, _[/COLOR]

Remove the & ".xls"

Code:
Dim wb_name As String

wb_name = ActiveWorkbook.Name


If WorksheetFunction.CountA(Range("J10:J33")) > 0 Then
'ChDir "C:\Users\Joseph\Desktop\Food Maxx Test\401"
ActiveWorkbook.SaveAs Filename:= _
"C:\Users\Joseph\Desktop\Food Maxx Test\401\" & wb_name, FileFormat:=xlExcel8, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False


End If
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,846
Messages
6,121,905
Members
449,054
Latest member
luca142

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