Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VBA Project locked for viewing password

33 views
Skip to first unread message

Paul S Ward

unread,
Jan 28, 2000, 3:00:00 AM1/28/00
to
Hi All:
Is it possible to change the VBA password from within code. SendKeys has
been suggested. Any ideas on code??

Bill Manville

unread,
Jan 29, 2000, 3:00:00 AM1/29/00
to
In article <86snf1$67d$1...@news7.svr.pol.co.uk>, Paul S Ward wrote:
> Is it possible to change the VBA password from within code. SendKeys has
> been suggested. Any ideas on code??
>
Needs reference to Visual Basic for Applications Extensibility Library

Sub SetVBProjectPassword(WB As Workbook, ByVal Password As String)
' used during making of new protected app, if user changes password
Dim VBP As VBProject, oWin As VBIDE.Window
Dim wbActive As Workbook
Dim i As Integer

Set VBP = WB.VBProject
Set wbActive = ActiveWorkbook

'can't do it if locked!
If VBP.Protection = vbext_pp_locked 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 lovely SendKeys to set the project password
Application.OnKey "%{F11}"
SendKeys "%{F11}%TE+{TAB}{RIGHT}%V{+}{TAB}" & Password & "{TAB}" &
Password & "~%{F11}", True

' leave no evidence of the password
Password = ""
' go back to the previously active workbook
wbActive.Activate
End Sub

Bill Manville
MVP - Microsoft Excel, Oxford, England
No email replies please - reply in newsgroup


0 new messages