VBA command for "save as..."

merlin_the_magician

Active Member
Joined
Jul 31, 2002
Messages
480
I have a template workbook that, when filled out, i want to save under a specific name.
Therefore, a value that should be part of the filename, can be entered in cell C1.

Question is... what VBA command to use, in order tp create a "save as" command, which includes the value in cell C1? :unsure:

filename should look like this: "[C1 value]specific filename.xls"
 
Command buttons... that is quite a bright idea allright...

one minor thing.... the "save" and "save as..." from the menu bar still can be opererated, which means one can STILL alter the filename (yes.... i'm quite demanding, i know....)
 
Upvote 0

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
merlin_the_magician said:
Command buttons... that is quite a bright idea allright...

one minor thing.... the "save" and "save as..." from the menu bar still can be opererated, which means one can STILL alter the filename (yes.... i'm quite demanding, i know....)

Put the following code in the ThisWorkbook module. It should do what you want.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

Dim ShName As String, FileName As String

ShName = "voorblad"
FileName = " kilometer declaratie"

ActiveWorkbook.SaveAs FileName:=Worksheets(ShName).[c1].Value & FileName & ".xls"

If SaveAsUI = True Then Cancel = True

End Sub
 
Upvote 0
Lovely ...!
One minor more thing... and i will stop bugging you for now. :)

As far as i have discovered, SaveUI does not exsist. Can i restrict that too?
 
Upvote 0
merlin_the_magician said:
Lovely ...!
One minor more thing... and i will stop bugging you for now. :)

As far as i have discovered, SaveUI does not exsist. Can i restrict that too?

I don't know what you mean by SaveUI does not exist. But whenever a SAVE or SAVEAS is performed then it would run that bit of code.
 
Upvote 0

Forum statistics

Threads
1,216,126
Messages
6,129,008
Members
449,480
Latest member
yesitisasport

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