I'm using the following macro to unlock my VBA projects when the workbook is opened. However if I already have another vba project unlocked, this macro will sometimes just place the password inside module and do nothing.
Is there a way to designate specifically which project should be unlocked?
Is there a way to designate specifically which project should be unlocked?
Code:
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
Private Sub Unlock_Project()
With Application
.SendKeys "%{F11}", True 'Alt-F11
Sleep 500
.SendKeys "^r", True 'CTRL+R
Sleep 500
.SendKeys "~", True 'enter
Sleep 500
.SendKeys ThisWorkbook.Password_M, True 'ThisWorkbook.Password_M is given a value when an earlier function is called
Sleep 500
.SendKeys "~", True 'enter
Sleep 500
.SendKeys "%q", True 'quit vba editor
End With
End Sub
Last edited: