Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 109
Default Using Send Keys to unprotect and protect VB project

I have a file which needs some code amending/ replacing. The project is
protected so I need to unprotect it before making any changes. I have
searhed this group and it would appear that SendKeys is the easiest way to
do it.

So far I have the following code, the unprotect part works fine but I am
unable to protect it again afterwards.

What I intend to do is have two xl files open, the fix file and the one to
be fixed. I will run the macro from the fix file.

Can anyone see where I'm going wrong?

Sub TestUnprotect()
Application.Windows(2).Activate
UnprotectVBProject ActiveWorkbook, "Gareth"
'update code, etc
End Sub

Sub TestProtect()
Application.Windows(2).Activate
ProtectVBProject ActiveWorkbook, "Gareth"
End Sub

Sub UnprotectVBProject(WB As Workbook, ByVal Password As String)
Dim vbproj As Object
Set vbproj = WB.VBProject
Set Application.VBE.ActiveVBProject = vbproj
SendKeys Password & "~~"
Application.VBE.CommandBars(1).FindControl(Id:=257 8,
recursive:=True).Execute
End Sub

Sub ProtectVBProject(WB As Workbook, ByVal Password As String)
Dim vbproj As Object
Set vbproj = WB.VBProject
Set Application.VBE.ActiveVBProject = vbproj
SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" & Password & "{TAB}" & Password & "~"
Application.VBE.CommandBars(1).FindControl(Id:=257 8,
recursive:=True).Execute
WB.Save
End Sub

I have no idea how the code works, just got it from a previous post.

Thanks in advance.



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
Protect, unprotect Pyrite Excel Discussion (Misc queries) 0 August 15th 08 03:18 PM
protect / unprotect VBA project by macro sylvain Excel Discussion (Misc queries) 0 July 31st 06 06:09 PM
Protect\Unprotect VBA project Rohit Thomas Excel Programming 2 August 28th 03 04:16 PM
Send Keys Akshay Bakhai Excel Programming 1 August 22nd 03 03:33 PM
Send Keys [email protected] Excel Programming 0 August 21st 03 08:13 PM


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