SAve file as a cell name

VbaHell

Well-known Member
Joined
Jan 30, 2011
Messages
1,220
Hello one and all

I am using excel 2007.
Is there a way please that when you click on the icon save that the file will be save as two cells using VBA.

IE Cell A1 = John
Cell S2 = 05/09/11
File name would save as A1 & - & S2

John-05/09/11
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Try like this in the ThisWorkbook module

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Cancel = True
Application.EnableEvents = False
Me.SaveAs Filename:=Sheets("Sheet1").Range("A1").Value & "-" & Format(Sheets("Sheet1").Range("S2").Value, "dd-mm-yyyy") & ".xls"
Application.EnableEvents = True
End Sub
 
Upvote 0
Hi Vog

This appears not to be working - I have saved the file but it is not renaming as per the VBA Code. If I look at Alt F11 the code is in Module tab under module1 is this correct please
 
Upvote 0
No, as I said, it goes in the ThisWorkbook module. In the VBA Project window double click ThgisWorkbook then paste in the code.
 
Upvote 0
Vog thank you for you help on this, Where do I insert code so that it saves in S:\Branch
 
Upvote 0
Try

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Cancel = True
Application.EnableEvents = False
Me.SaveAs Filename:="S:\Branch\" & Sheets("Sheet1").Range("A1").Value & " " & Format(Sheets("Sheet1").Range("S2").Value, "dd-mm-yyyy") & ".xls"
Application.EnableEvents = True
End Sub
 
Upvote 0
Hi Vog


I have pasted this into the "Thisworkbook" module but it is still not saving correctly.
It keeps saving as the name of the orginal file instead of the cells B13 & G13, I know I am being a nusance on this but if you could spot my mistake that would be great.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Cancel = True
Application.EnableEvents = False
Me.SaveAs Filename:="S:\Branch\" & Sheets("Sheet1").Range("B13").Value & " " & Format(Sheets("Sheet1").Range("G13").Value, "dd-mm-yyyy") & ".xls"
Application.EnableEvents = True
End Sub
 
Upvote 0
This worked fine for me

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim Fname As String
Cancel = True
Application.EnableEvents = False
Fname = "F:\" & Sheets("Sheet1").Range("B13").Value & " " & Format(Sheets("Sheet1").Range("G13").Value, "dd-mm-yyyy") & ".xlsm"
MsgBox Fname
Me.SaveAs Filename:=Fname, FileFormat:=52
Application.EnableEvents = True
End Sub

Maybe events are disabled. Press CTRL + G to open the Immediate Window, enter

Application.EnableEvents = True

and press Enter. Then try again.
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,153
Members
452,891
Latest member
JUSTOUTOFMYREACH

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