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