Add Password Proction when selecting Save As to the Workbook

Sonyafm

New Member
Joined
Mar 3, 2015
Messages
18
Hi,

I have a Workbook that users should be able to open and work on. But users shouldn't be able to save the workbook on their computer. How can I add a password protection when someone clicks Save As and Save?

I included the code below to the Excel Object "This workbook" but it's not working. I put a breakpoint on that row to see if reads the code and it doesn't. What am I missing here?

ThisWorkbook.SaveAs Password:="Password"
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
That code is setting a password on the saved file. It is not preventing the SaveAs.

This code, in the ThisWorkbook code module, will prevent the user from using SaveAs unless they enter a case sensitive password.


Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    If SaveAsUI Then
        Cancel = (Application.InputBox("Password please", Type:=2) <> "password")
        If Cancel Then MsgBox "wrong password"
    End If
End Sub

Like all Excel protection features, its is easy to defeat.
IMO, Excel is so far from a secure platform that big effort to protect a workbook or worksheet from unauthorized use aren't worth the effort.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,561
Messages
6,114,317
Members
448,564
Latest member
ED38

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