Save As w/ Password Protect

xMIKExSMITHx

New Member
Joined
Jul 11, 2014
Messages
41
I have a few custom add-ins using various coding for specific work related tasks. At work, we password protect all our files. I am wondering if there is a specific code that I can add to my custom add-ins sheet that I would click and it would automatically do a Save As with a specified pw I set in the coding without having to go through the actual save as screen and general options setting.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

GR00007

Board Regular
Joined
Apr 22, 2015
Messages
184
Here's the syntax for save as:
https://docs.microsoft.com/en-us/office/vba/api/excel.workbook.saveas

Besides password, you also add WriteResPassword which will allow the workbook to open without a password, but only in read only mode.
To avoid the 'are you sure' prompts change display alerts
Code:
    Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs Filename:=vDir & vSaveName, _
        FileFormat:=version, Password:="whatever", WriteResPassword:="if-needed", _
        ReadOnlyRecommended:=False, CreateBackup:=False
    Application.DisplayAlerts = True
Caution: are you sure your macro is in a completely safe place where only authorized people can access the code?
 

xMIKExSMITHx

New Member
Joined
Jul 11, 2014
Messages
41
Hi GR,

Much obliged for the help. To answer your question, my add ins are on my work laptop on the desktop. Only I have access to and use them to make me work more efficient. They are all tailored to my specific roles like formatting a specific report I do and a few other ones. My main goal for this was to shave off the crucial time wasted on the mundane Save As--->General Options--->Type PW twice thing. Precious time being wasted when all my files need to be PW protected. Haha.
 
Last edited:

xMIKExSMITHx

New Member
Joined
Jul 11, 2014
Messages
41
I meant to reply directly to your post. Still getting used to the message boards....see my response below. :LOL:
 

GR00007

Board Regular
Joined
Apr 22, 2015
Messages
184
I meant to reply directly to your post. Still getting used to the message boards....see my response below. :LOL:
No prob - I'm getting used to 'em as well - when I first saw 'Reply with quote' I had the thought it was giving the amount needed to do consulting stuff.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,016
Messages
5,834,943
Members
430,327
Latest member
Mr_Himalayan778

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
Top