ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how to protect sheets from VBA? (https://www.excelbanter.com/excel-programming/292039-how-protect-sheets-vba.html)

jon

how to protect sheets from VBA?
 
I need to protect all of the sheets in my AddIn before I release it, but I
don't want them to be protected while I'm doing development. Is there any
way to protect the sheets when the AddIn is loaded, or at some other time?
I'm using Excel 97...

:)

Jon



pauluk[_74_]

how to protect sheets from VBA?
 
Why do you not just password protect the addin?

Or create a simple macro to protect the sheets and unprotect whe
working on them.

i.e place an admin macro in the addin so its locked when others use i
but when you need to ammend something you can click admin and put th
password in which then unlock the sheets.

Below is some code which may help you, or you can use a simple cod
also below
<=====Code that i have found=======

Sub modMenu_Administer()
On Error GoTo err_modMenu_Administer
'vars
Dim strTemp As String

'code
strTemp = InputBox("Please enter password to unlock thi
workbook")
If strTemp = sysCurrentPW Then
sysUnlockWorkbook
Else
If strTemp < "" Then
MsgBox "Password incorrect"
End If
End If

'gotos
exit_modMenu_Administer:
Exit Sub

err_modMenu_Administer:
MsgBox Err & " - " & Error()
Resume exit_modMenu_Administer


End Sub

Sub sysLockWorkbook()
On Error GoTo err_LockWorkbook

'vars

'code
Sheets("Personal Details").Protect sysCurrentPW
Sheets("Log").Protect sysCurrentPW
Sheets("System").Visible = False
Sheets("modSystem").Visible = False
Sheets("modMenu").Visible = False
Sheets("modDetails").Visible = False
Sheets("frmDetails").Visible = False
Sheets("modLog").Visible = False
Sheets("frmLog").Visible = False
Sheets("Lists").Visible = False
Sheets("frmPrint").Visible = False
Sheets("modPrint").Visible = False
Sheets("modOutput").Visible = False
Sheets("frmOutput").Visible = False
Sheets("tmpLog").Visible = False


sysMenusVisible False
sysToolBarsVisible False
'gotos
exit_LockWorkbook:
Exit Sub

err_LockWorkbook:
MsgBox Err & " - " & Error()
Resume exit_LockWorkbook
Resume
End Sub



Sub sysUnlockWorkbook()
On Error GoTo err_UnlockWorkbook

'vars
Dim objToolbar As Object


'code
Sheets("Personal Details").Unprotect sysCurrentPW
Sheets("Log").Unprotect sysCurrentPW
Sheets("System").Visible = True
Sheets("modSystem").Visible = True
Sheets("modMenu").Visible = True
Sheets("modDetails").Visible = True
Sheets("frmDetails").Visible = True
Sheets("modLog").Visible = True
Sheets("frmLog").Visible = True
Sheets("Lists").Visible = True
Sheets("frmPrint").Visible = True
Sheets("modPrint").Visible = True
Sheets("modOutput").Visible = True
Sheets("frmOutput").Visible = True
Sheets("tmpLog").Visible = True

sysMenusVisible True
sysToolBarsVisible True
'gotos
exit_UnlockWorkbook:
Exit Sub

err_UnlockWorkbook:
MsgBox Err & " - " & Error()
Resume exit_UnlockWorkbook

End Su

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 05:53 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com