N
Nessy via OfficeKB.com
After reading a number of threads on this website, I have managed to define a
password for the VBProject in Workbook, WB, by making use of the following
code. However, I would also like to automatically set the option 'Lock
project for viewing' to True by code. Can anyone help, what do I need to do?
Public Sub ProtectCodeModule(ByVal WB As Workbook, Password as string)
Dim VBP As VBProject, oWin As VBIDE.Window
Dim wbActive As Workbook
Dim i As Integer
Set VBP = WB.VBProject
Set wbActive = WB
If VBP.Protection <> vbext_pp_none Then Exit Sub
Application.ScreenUpdating = False
' Close any code windows to ensure we hit the right project
For Each oWin In VBP.VBE.Windows
If InStr(oWin.Caption, "(") > 0 Then oWin.Close
Next oWin
WB.Activate
' Now use SendKeys to write password
Application.OnKey "%{F11}"
SendKeys "%{F11}%TE" & Password & "~~%{F11}", True
End Sub
Thanks in anticipation.
password for the VBProject in Workbook, WB, by making use of the following
code. However, I would also like to automatically set the option 'Lock
project for viewing' to True by code. Can anyone help, what do I need to do?
Public Sub ProtectCodeModule(ByVal WB As Workbook, Password as string)
Dim VBP As VBProject, oWin As VBIDE.Window
Dim wbActive As Workbook
Dim i As Integer
Set VBP = WB.VBProject
Set wbActive = WB
If VBP.Protection <> vbext_pp_none Then Exit Sub
Application.ScreenUpdating = False
' Close any code windows to ensure we hit the right project
For Each oWin In VBP.VBE.Windows
If InStr(oWin.Caption, "(") > 0 Then oWin.Close
Next oWin
WB.Activate
' Now use SendKeys to write password
Application.OnKey "%{F11}"
SendKeys "%{F11}%TE" & Password & "~~%{F11}", True
End Sub
Thanks in anticipation.