Password protecting an Excel file (1 Viewer)

aziz rasul

Active member
Local time
Today, 06:13
Joined
Jun 26, 2000
Messages
1,935
I have the following snippet of code

Code:
objExcelAppOriginal.ActiveWorkbook.Sheets(strWorksheet).Protect Password:=strPassword, DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFiltering:=True

and

Code:
With objExcelAppOriginal
   .ActiveWorkbook
   .Protect Password:=strPassword, Structure:=True, Windows:=False
   .Save
   .Close
End With

I get no errors but the file opens without prompting me with a password!
 

Ranman256

Well-known member
Local time
Today, 01:13
Joined
Apr 9, 2015
Messages
4,337
try the SaveAs , but overwrite the existing file
Code:
Application.DisplayAlerts = [COLOR=#000080]False
[/COLOR]ActiveWorkbook.SaveAs Filename, , Password
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 15:13
Joined
Jan 20, 2009
Messages
12,853
I have the following snippet of code

Code:
objExcelAppOriginal.ActiveWorkbook.Sheets(strWorksheet).Protect Password:=strPassword, DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFiltering:=True
and

Code:
With objExcelAppOriginal
   .ActiveWorkbook
   .Protect Password:=strPassword, Structure:=True, Windows:=False
   .Save
   .Close
End With
I get no errors but the file opens without prompting me with a password!

Protect prevents protected cells from being changed. It isn't intended to require a password to open the workbook.
 

Users who are viewing this thread

Top Bottom