This vba macro example, sets password to excel file named "excel.xls". This example assumes excel file named "excel.xls" already open.
Sub ProtectExcel()
'write password
Workbooks("excel.xls").Password = "macroexcel"
'save workbook
Workbooks("excel.xls").Save
End Sub
This example opens the protected excel file named "excel.xls" on the D:\ drive.
Sub OpenProtectedExcel()
'open protected excel file
Workbooks.Open Filename:="D:\excel.xls", _
Password:="macroexcel"
End Sub
This example remove protection from worksheet named "Sheet1" and protect it with new password.
Sub xProtect()
'Assumes excel.xls already open
'unprotect sheet
Workbooks("excel.xls").Sheets("Sheet1").Unprotect "password"
'protect sheet with new password
Workbooks("excel.xls").Sheets("Sheet1").Protect "vbamacro"
'save changes
Workbooks("excel.xls").Save
End Sub
Thank you for reading this article Excel VBA Macro Example: Protect & Unprotect Worksheet/Excel File With URL https://x-tutorials.blogspot.com/2009/02/excel-vba-macro-example-protect.html. Also a time to read the other articles.
0 comments:
Write your comment for this article Excel VBA Macro Example: Protect & Unprotect Worksheet/Excel File above!