Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Lock VBProject for Viewing using Code

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007 - Lock for viewing Ed Excel Discussion (Misc queries) 0 January 16th 07 11:35 PM
Excel crashes when adding code using vbproject object? mikeb Excel Programming 5 May 8th 06 11:57 PM
Lock Project for Viewing..HELP ME And1 Excel Programming 0 November 26th 05 08:22 PM
Unlock/Lock VBProject through code? dominicb[_97_] Excel Programming 0 August 24th 05 10:54 PM
Unlock/Lock VBProject through code? djvice Excel Programming 0 August 24th 05 10:08 PM


All times are GMT +1. The time now is 02:12 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"