View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Lock VBProject for Viewing using Code

This looks like an example of Bill Manville's that has been plagiarized on
whatever site you found it.

Application.OnKey "%{F11}"

I think you can comment the above but change the following
SendKeys "%{F11}%TE" & Password & "~~%{F11}", True

to
SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" & Password & "{TAB}" & Password & "~"

Regards
Peter T

"Nessy via OfficeKB.com" <u5428@uwe wrote in message
news:6727c24b0e7b2@uwe...
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.

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200610/1