Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 269
Default unlocking VBA project programatically

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

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
Unlocking Project When Condition is Met Orion Cochrane Excel Programming 2 August 22nd 08 07:26 PM
Unlocking VBA project in Excel Ramkumar Viswanathan Excel Programming 0 June 6th 06 08:04 AM
Programatically Unlocking a Project in the VBIDE Jim Thomlinson[_5_] Excel Programming 2 January 5th 06 10:07 PM
Unlocking a Project Ralph Heidecke[_2_] Excel Programming 3 December 29th 05 04:39 PM
unlocking a project in VB(A) Arne[_2_] Excel Programming 4 July 30th 03 09:29 AM


All times are GMT +1. The time now is 02:10 AM.

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"