Password protecting an Excel file

aziz rasul

Active member
Local time
Today, 16:25
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!
 
try the SaveAs , but overwrite the existing file
Code:
Application.DisplayAlerts = [COLOR=#000080]False
[/COLOR]ActiveWorkbook.SaveAs Filename, , Password
 
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

Back
Top Bottom