VBA Saving File Name

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,124
Office Version
  1. 365
Platform
  1. Windows
Good Day All,

I have a *.xlsm file that is saved as title "ddmmmyyyy ExcelFile.xlsm".

Sometimes in using slower computers in using this file its name gets edited without the user consent when it is saved.

How would I prevent the excel file from saving itself as a different name as titled above?

For example, if I have;

"29APR2023 ExcelFile.xlsm" How would I prevent it from it being saved as "29APR2023 ExcelFile-ComputerName .xlsm" or anything other then "29APR2023 ExcelFile.xlsm"?

Is there a sub that someone has that they can share on this topic?

Please let me know.

Many thanks in advance!

Respectfully,
pinaceous
 

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.
Put this code in the Workbook Code Module.

It seems to prevent the user saving the file under a different name by disabling the options on
the Save As dialog screen.

Remember to password protect your VBA code as users could change or delete this sub.

VBA Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

    If SaveAsUI = True Then
        Cancel = True
    End If

End Sub
 
Upvote 0
seems to prevent the user saving the file under a different name by disabling the options on
the Save As dialog screen.

Herakles,​


Interesting. Very interesting.

I do appreciate this code!

But I believe that the computer is acting independently from the user for "this" purpose.

I'll have to run this sub upon one of my files to see if it will happen again because I do not think that the user is allowing the name change.

If any changes to the sub as per my description, please let me know!

Thanks again!

Respectfully,
pinaceous
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,109
Members
452,302
Latest member
TaMere

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