VBA to force a file to be named using a certain format

austin397

New Member
Joined
Dec 16, 2016
Messages
36
I would like to make a way so that when the user saves it will force them to save the file a certain way,

Ex. "XX-xxXXxx-x BOM" Where XX equals letters and xx equals numbers.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hello austin397,

Is the user entering the file name before saving the file or will the file name be generated automatically when the user saves the file?
 
Upvote 0
I don't reckon you can force a file to be named a certain way once in the save as window, but maybe you could work something out with input boxes.

Code:
val1 = InputBox("Write 2 letters")
val2 = InputBox("Write 2 numbers followed by two letters followed by 2 numbers")
val3 = InputBox("Write 2 letters")
And then save it as ""&val1&"-"&val2&"-"&val3&" BOM.filetype"
You could then add some checks to determine if the user wrote exactly the amount of symbols which is required.
Of course, this is not a very elegant way, so if someone else has a better option..
 
Upvote 0
The user will be entering the file name. I only want them to be forced to name it following a specific format.

Thank you for your reply!
 
Upvote 0
Hello austin397,

Where is the user entering the file name: Worksheet, VBA UserForm, SaveAs Dialog?
 
Upvote 0
Either on a VBA UserForm or the save as Dialogue box is fine. If it's in the worksheet the user will easily forget to do it.

Thanks!
 
Upvote 0
Hello austin397,

A VBA UserForm would be best. It gives you the most control and flexibility with data entry.

I take it that you don't already have a UserForm in your workbook. Would you like me to create a sample workbook with a UserForm to do this?

I can post a link to the sample workbook since I can not post one here.
 
Last edited:
Upvote 0
If you can do that, that would be great! If you don't want to go through the trouble of that, just a sample VBA code should do.

Thanks!
 
Upvote 0
Hello austin397,

It isn't any trouble to do. I would need the UserForm anyway to write the VBA code.
 
Last edited:
Upvote 0
Hello austin397,

I have the UserForm and it's code complete. But, I have a question. Will this code be added to your Personal.xls workbook?

If not then will this macro be saving another open workbook?
 
Upvote 0

Forum statistics

Threads
1,202,901
Messages
6,052,445
Members
444,581
Latest member
naninamu

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