A "Save As" Macro

ILeonFF

New Member
Joined
Jun 20, 2018
Messages
18
Is it possible that when i save a workbook, a macro would look at a cell and save it as what is ever in that cell and partially keep the original name?

Current file name: Applications_Form
What i am looking for the macro to do is; look at K1 (123456) and add it to the original file name so when i execute the save command it would look like this;
New File Name: 123457_Applications_Form.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try this, you need to specify the path for your save folder make sure path ends with \, this is xls, if you need other filetype change it as needed

Code:
Sub filename_cellvalue()


Dim Path As String
Dim filename As String
Path = "C:\path\" 'enter filepath here
filename = Range("K1")
ActiveWorkbook.SaveAs filename:=Path & filename & "_Applications_Form" & ".xls", FileFormat:=xlNormal


End Sub
 
Upvote 0
Try this, you need to specify the path for your save folder make sure path ends with \, this is xls, if you need other filetype change it as needed

Code:
Sub filename_cellvalue()


Dim Path As String
Dim filename As String
Path = "C:\path\" 'enter filepath here
filename = Range("K1")
ActiveWorkbook.SaveAs filename:=Path & filename & "_Applications_Form" & ".xls", FileFormat:=xlNormal


End Sub

If multiple users are using this, is there a generic pathing for a desktop save.

for example would this work:

"C:\Users\Desktop"
 
Upvote 0
If multiple users are using this, is there a generic pathing for a desktop save.

for example would this work:

"C:\Users\Desktop"

Code:
Sub SaveWorkbook()
  Dim Prefix As String
  Dim NewPath As String
  Prefix = ThisWorkbook.Sheets("Sheet1").Range("K1").Text
  NewPath = "C:\Users\" & Environ("UserName") & "\Desktop\" & Prefix & "_" & ThisWorkbook.Name
  ThisWorkbook.SaveAs NewPath
End Sub
 
Upvote 0
Code:
Sub SaveWorkbook()
  Dim Prefix As String
  Dim NewPath As String
  Prefix = ThisWorkbook.Sheets("Sheet1").Range("K1").Text
  NewPath = "C:\Users\" & Environ("UserName") & "\Desktop\" & Prefix & "_" & ThisWorkbook.Name
  ThisWorkbook.SaveAs NewPath
End Sub


Code runs, so no errors there however its just naming the file _Applications_Form. Its not adding anything that was in the K1 sheet.

Disregard the above^^^
It works perfect, thank you so much
 
Last edited:
Upvote 0
Code runs, so no errors there however its just naming the file _Applications_Form. Its not adding anything that was in the K1 sheet.

It's cos there's nothing in cell K1 on Sheet1. You need to change the name of the sheet in the macro, so that it matches the name of the sheet in which K1 has the value!
 
Upvote 0
It's cos there's nothing in cell K1 on Sheet1. You need to change the name of the sheet in the macro, so that it matches the name of the sheet in which K1 has the value!

Yeah i changed everything i needed. I kept looking at it and was wondering what was wrong. It was supposed to be K7 not K1, just had a brain-fart and couldn't differentiate the two
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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