Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Protect, unprotect | Excel Discussion (Misc queries) | |||
protect / unprotect VBA project by macro | Excel Discussion (Misc queries) | |||
Protect\Unprotect VBA project | Excel Programming | |||
Send Keys | Excel Programming | |||
Send Keys | Excel Programming |