save file with name equal to cell content (revised)

22868

New Member
Joined
Apr 4, 2002
Messages
13
Hi all,

New challange........... (for me anyway).

Base case: Worksheet based on template

I am trying to to have Excel generate\suggest a specific save path\name for the work sheet as soon as I hit "save" or "save as". Name should be equal to the content of 2 cells in the worksheet.

e.g.:

cell A1=15
cell B1=5-Oct-05

hit save or save as and path suggested will be:

c:\match results\game-15 (5-Oct-05)

I am a VBA novice so explain it to me like I am a 4 year old :o

Thanks!

Pete
 
Got half the answer

Hi 22868,

I've got 1/2 the answer for you...

If:
A1: 15
B1: 5-Oct-05
Add:
C1: _( "replace the underscore with a blank space...
D1: )
E1: =A1&C1&TEXT(B1,"d-mmm-yy")&D1

Then, whenever you change A1 or B1, the value of E1 should look like
ex:
27 (13-Dec-06)

Now for the Macro,

Sub ReNameFile()
ActiveWorkbook.SaveAs FileName:=Range("E1").Value
'value in E1, ex 27 (13-Dec-06)
End Sub

Once you "Run" the macro, the name of you workbook will change automatically from: YourTemplateFile.xls to: 27 (13-Dec-06).xls
Your Template will remain unchanged.

Let me know if it works, as for saving it in a specific path/folder (c:\match results\), you could go to “Tools” > “Options or Properties or something?” a greyish window with about 12 tabs will appear, one of them, “General” I believe, will have a field to input the default location for saving the file. Sorry for the lack of precision here, I’m using a Mac and the steps are a little different from when I use the PC at work.


If you do find a macro to “Save As” with a specific path / folder, let me know.
I’m also trying to do the same, based on... if A, same in Folder A, if B, save in Folder B.
Obviously, the above “Tools” option limits you to 1 field/location.


Cheers,
Sprucy
 
Upvote 0
Hi Sprucy,

Thanks for the macro. Its running like clock work except for the fact that I have to manually run it. Any idea on how to create the file name as soon as I create the workbook from the template?

Thanks in advance,

Pete
 
Upvote 0
Hey Pete,

Sorry, I'm just learning myself.
I'll let you know if I figure it out.

Good luck,
Sprucy
 
Upvote 0
Hi Pete,

Try this one out...
----------------------------
Sub SaveAs()
'specify the name of your sheet
Worksheets("sheet1").Copy
Dim filename As String, path As String, savefile As String
'Change to "S:\....soc\......
path = "c:\match results\" ' add subfolders if needed, but must end with \
filename = Range("E1").Value 'your cell should be??
savefile = path & filename & ".xls"
ActiveWorkbook.SaveAs savefile
'
Workbooks("theNameofyourMasterFile.xls").Saved = True 'True, will NOT saves changes, False will...
Workbooks("theNameofyourMasterFile.xls").Close True
'This will close your master automatically.

End Sub
-----------------------------

By all means, clean-up the macro by removing all excess 'remarks.

Now, if you master file is Games.xls, once you modify the file, Run macro, all changes will be Save As ex:
27 (13-Dec-06)
in the specified path C:\match result\
the final/full path will of course be: c:\match result\27 (13-Dec-06).xls

And Games.xls will close automatically unchanged.
 
Upvote 0

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