I had to do something similar and access a password protected VBA module
I found this snippet somewhere in this discussion group.
Application.Wait (25)
SendKeys "%({F11})", True
Set Application.VBE.ActiveVBProject = ActiveWorkbook.VBProject
SendKeys "%(TE)" & "password" & "~~%({F11})", True
I used it once I found and opened a file. I am not sure exactly how or why
it worked, but it usually succeeded in programatically entering the password
to unprotect the VBA module.
If I recall correctly, every so often it would miss one as it was looping
through and I had to manually enter the password then it would work again for
a while.
Not exactly robust code, but it did the job.
"Pranav Vaidya" wrote:
Hi,
I have more than 100 Excel files which contain a VBA project. This VBA
project is password protected. I know the password, it is the same for all
these Excel files. I need to remove password of these files programtically. I
am using VB 6 and Excel 2003.
So far I am able to reasch the "VBAProject Password" window, obtain handle
to command button OK.
I am not able to get the handle to "Password" text box.
My code returns nothing at line
hWndPassword = GetDlgItem(hWndProjectProperties, ControlIDPassword)
Below is my code
Const ControlIDOK As Long = &H1&
Const ControlIDPassword As Long = &H1555&
Dim ctrl As Office.CommandBarControl
Dim hwnd As Long
Dim hWndPassword As Long
Dim hWndOK As Long
With proj
With .VBE
' Find Project Properties dialog
Set ctrl = .CommandBars.FindControl(Id:=2578)
' Display Project Properties dialog
ctrl.Execute
Set ctrl = Nothing
End With
End With
' Get hWnd for Project Properties dialog
hWndProjectProperties = FindWindow(vbNullString, "VBAProject Password")
If hWndProjectProperties = 0 Then
Exit Sub
End If
' Get hWnd for OK button in Project Properties dialog
hWndOK = GetDlgItem(hWndProjectProperties, ControlIDOK)
strPassword = "passwd"
' Get hWnd for Password Edit control in Project Properties dialog
hWndPassword = GetDlgItem(hWndProjectProperties, ControlIDPassword)
SendMessage hWndPassword, EM_REPLACESEL, vbTrue, ByVal strPassword
'OK button
SetFocusAPI hWndOK
SendMessage hWndOK, BM_CLICK, 0&, 0&
I have taken this code from
http://www.standards.com/Office/SetV...tPassword.html
Thanks in advance.
--
Pranav Vaidya
VBA Developer
PN, MH-India