How to UnProtect an Active Project with a Known Password?

FENGJUN

New Member
Joined
May 21, 2007
Messages
4
How to UnProtect an Active Project with a Known Password?

I have asked so many times in so many Excel Forums, Until now did NO anwer come to me!

Can U give me What I need?
thank U a lot!
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Are you referring to a vba project? If so, juct open the VBE and you will be prompted to enter a password.
 
Upvote 0
Are you referring to a vba project? If so, juct open the VBE and you will be prompted to enter a password.

Thanks for ur answer. But what I want to know eactly is How to Unprotect a VBA Project with a known password WITH VBA CODE? By the way I don't want to use The Sendkey method.
 
Upvote 0
the following code can not work in Excel 2003:

why?

--------------------------------------------------------------------------

'need reference To VBA Extensibility
'need To make sure that the target project Is the active project
Sub test()
UnprotectVBProject Workbooks("ABook.xls"), "password"
End Sub

Sub UnprotectVBProject(WB As Workbook, ByVal Password As String)
'
' Bill Manville, 29-Jan-2000
'
Dim VBP As VBProject, oWin As VBIDE.Window
Dim wbActive As Workbook
Dim i As Integer

Set VBP = WB.VBProject
Set wbActive = ActiveWorkbook

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 unprotect
Application.OnKey "%{F11}"
SendKeys "%{F11}%TE" & Password & "~~%{F11}", True

If VBP.Protection = vbext_pp_locked Then
' failed - maybe wrong password
SendKeys "%{F11}%TE", True
End If

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

End Sub

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub ProtectVBProject(WB As Workbook, ByVal Password As String)

Dim VBP As VBProject, oWin As VBIDE.Window
Dim wbActive As Workbook
Dim i As Integer

Set VBP = WB.VBProject
Set wbActive = ActiveWorkbook

' 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 unprotect
Application.OnKey "%{F11}"
SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" & Password & "{TAB}" & Password & "~"
Application.VBE. CommandBars(1).FindControl(Id:=2578, recursive:=True).Execute
WB.Save
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Code:
 
Upvote 0
Do you have an error message of some sort?

You need to 'Trust Access to the Visual Basic Project', perhaps?

Tools->Macro->Security... Go to the 'trusted sources' tab and note the last checkbox in the dialog.

This is going to be a problem if you're working on something that is distributed... Access is not trusted by default in Excel XP+, including Excel 2003.

Did you try my code?
 
Upvote 0
Nate, I never knew Sendkeys exsisted. I am having a blast with it. Do you know of a chart or such that shows how to work combinations? such as +
I gather that % is alt. what about ctrl? shift? and so on? What about holding keys while you send another? ctrl+p? -yes I know how to print with out this, just want to see how to add +:)
Thanks for the help and the link!
 
Upvote 0
Do you have an error message of some sort?

You need to 'Trust Access to the Visual Basic Project', perhaps?

Tools->Macro->Security... Go to the 'trusted sources' tab and note the last checkbox in the dialog.

This is going to be a problem if you're working on something that is distributed... Access is not trusted by default in Excel XP+, including Excel 2003.

Did you try my code?

Many thanks TO NateO! Now the above Code can work.

your Code?——

Sub tryThis()

Application.SendKeys "Range", True

Application.SendKeys "~", True

Application.Goto Reference:="tryThis"

Application.SendKeys "%{f4}"

End Sub

——Sorry, I really don't understand what it is going to do.
 
Upvote 0
Nate, I never knew Sendkeys exsisted. I am having a blast with it. Do you know of a chart or such that shows how to work combinations? such as +
I gather that % is alt. what about ctrl? shift? and so on? What about holding keys while you send another? ctrl+p? -yes I know how to print with out this, just want to see how to add +
Thanks for the help and the link!

If you search for "Sendkeys Statement" in the VBE help files, it will give you a list showing how to refer to given keys.
 
Upvote 0

Forum statistics

Threads
1,215,723
Messages
6,126,470
Members
449,315
Latest member
misterzim

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top