VBA to save file as cell name in XLSM, in current folder location

Papinu

New Member
Joined
Mar 17, 2017
Messages
6
Hello, I'm hoping somebody can help with VBA for me to save a file using cell name in current file format which is XLSM.

Many thanks
 
Remember to add a backslash after the path...

Code:
Sub save_progress()
[COLOR=#ff0000]Application.DisplayAlerts = False[/COLOR]
Dim getP As String
Dim wbname As String
getP = Application.ActiveWorkbook.Path [COLOR=#ff0000]& "\"[/COLOR]
wbname = Range("a1").Value
ActiveWorkbook.SaveAs Filename:=getP & wbname & ".xlsm"
[COLOR=#ff0000]Application.DisplayAlerts = True[/COLOR]
End Sub

Cheers,

tonyyy
 
Last edited:
Upvote 0

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).
Remember to add a backslash after the path...

Code:
Sub save_progress()
[COLOR=#ff0000]Application.DisplayAlerts = False[/COLOR]
Dim getP As String
Dim wbname As String
getP = Application.ActiveWorkbook.Path [COLOR=#ff0000]& "\"[/COLOR]
wbname = Range("a1").Value
ActiveWorkbook.SaveAs Filename:=getP & wbname & ".xlsm"
[COLOR=#ff0000]Application.DisplayAlerts = True[/COLOR]
End Sub

Cheers,

tonyyy

Good tip, Tony. I had it in the cell; but wasn't thinking it all the way through for the end user.
 
Upvote 0
This seems to do the trick:

Code:
 Sub save_progress()
 
 Dim wbname As String
 Dim pathONLY, filePATH, fileONLY As String
 filePATH = ThisWorkbook.FullName
 fileONLY = ThisWorkbook.Name
 pathONLY = Left(filePATH, Len(filePATH) - Len(fileONLY))
 wbname = Range("a1").Value
 On Error Resume Next
 ActiveWorkbook.SaveAs Filename:=pathONLY & wbname & ".xlsm"
 
 End Sub




Thanks dUBBINS. This works perfectly. What change would I make to have a save dialog box appear though?

Also, how do you add that code window in the reply?

:)
 
Upvote 0
I am sorry, I thought you had asked for now dialog box. I will check on how to make it pop up.

To create the window, you put this before the code (without the spaces, the spaces are necessary to show you without triggering the actual window):

[ c o d e ]

And this after your code (without the spaces):

[ / c o d e ]
 
Upvote 0
Thanks dUBBINS. This works perfectly. What change would I make to have a save dialog box appear though?

Also, how do you add that code window in the reply?

:)

Code:
Sub save_progress()
Dim wbname As String
 Dim pathONLY, filePATH, fileONLY As String
dim answer as string
dim note as string
note="Save?"

 filePATH = ThisWorkbook.FullName
 fileONLY = ThisWorkbook.Name
 pathONLY = Left(filePATH, Len(filePATH) - Len(fileONLY))
 wbname = Range("a1").Value
answer=msgbox(note,vbquestion + vbyesno, "???")
if answer = vbyes then
 On Error Resume Next
 ActiveWorkbook.SaveAs Filename:=pathONLY & wbname & ".xlsm"
 else
msgbox "File was not saved."
end if
 End Sub

I think this will do what you want. I just built a save dialog box, because I couldn't find a way to do it without using Save as...and you have it automatically saving a name, so I figured you don't want people saving it as anything but what you tell it to.
 
Upvote 0
Thanks dUBBINS. You've been a big help. I think I'll stick with the autosave. It does exactly what I'm after. Thank you again :)
 
Upvote 0

Forum statistics

Threads
1,215,646
Messages
6,126,004
Members
449,279
Latest member
Faraz5023

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