On 2002-04-18 00:11, mnmhenry wrote:
I was reading with interest about deleting a macro with a macro from a previouse question. My Macros are protected in VB so no one can veiw / alter them. I have tried to delete / alter a macro using this method, but I cant as it stops as the macro's are locked ...... Can this be done ??
Here is one way to do this provided you
know the password
<pre/>
Sub UnprotectVBProject()
Dim wbproj As Object
On Error Resume Next
Set wbproj = ActiveWorkbook.VBProject
Application.SendKeys "test", True
Application.SendKeys "~", True
wbproj.VBE.SelectedVBComponent.Activate
On Error GoTo 0
End Sub
</pre>
Here is another one I posted some years ago
</pre>
Option Explicit
Const BreakIt As String = "%{F11}%TE+{TAB}{RIGHT}%V{+}{TAB}"
Sub Change_VBA_PW()
Dim WB As Workbook
Dim Password As String
Set WB = ActiveWorkbook
Password = "ivan"
Call SetVBProjectPassword(WB, Password)
End Sub
Sub SetVBProjectPassword(WB As Workbook, ByVal Password As String)
'Needs reference to Visual Basic for Applications Extensibility Library
Dim VBP As VBProject
Dim OpenWin As VBIDE.Window
Dim i As Integer
Set VBP = WB.VBProject
Application.ScreenUpdating = False
' close any code windows to ensure we are in the right project
For Each OpenWin In VBP.VBE.Windows
If InStr(OpenWin.Caption, "(") > 0 Then OpenWin.Close
Next OpenWin
WB.Activate
SendKeys BreakIt & Password & "{tab}" & Password & "~" & "%{F11}~", True
'SendKeys "enter", True
WB.Activate
SendKeys "%{F11}", True
Application.ScreenUpdating = True
End Sub
</pre>
Thanks Guys.
Mark.