Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Unlock VBA Project after getting wrong first time

I need to be able to unlock the VBA Project within my code. I have
used the following code that I found on the net

Private Sub UnprotectVBProject(WB As Workbook, ByVal Password As
String)
Dim vbProj As VBIDE.VBProject

Set vbProj = WB.VBProject

'can't do it if already unlocked!
If vbProj.Protection < 1 Then Exit Sub

Set Application.VBE.ActiveVBProject = vbProj

' now use lovely SendKeys to quote the project password
SendKeys Password & "~~"

Application.VBE.CommandBars(1).FindControl(ID:=257 8,
recursive:=True).Execute

SendKeys "{ESC}"

DoEvents
End Sub


This code works fine when used first time. The problem is, if the user
types the wrong password in, then I call the same routine, it leaves
the Project Properties form on the screen, although it has correctly
unlocked the project.

Can someone please help?
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
Is there a way to unlock a project in VBA if you know the password DaveO Excel Programming 1 July 4th 06 10:39 AM
Unlock VBA project Tomasz Klim Excel Discussion (Misc queries) 0 October 10th 05 03:43 PM
Unlock VBA Project zhj23 Excel Programming 1 October 8th 05 12:50 PM
Unlock VBA Project zhj23 Excel Discussion (Misc queries) 1 October 8th 05 12:14 PM
Unlock VBA project Gail Kling[_2_] Excel Programming 8 August 31st 04 06:25 PM


All times are GMT +1. The time now is 12:40 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"