View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Pranav Vaidya Pranav Vaidya is offline
external usenet poster
 
Posts: 180
Default unlocking VBA project programatically

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