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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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,224,828
Messages
6,181,204
Members
453,022
Latest member
RobertV1609

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