0

Below the VBA code but I can not manage it. Is there any way to open VBA code from other VBA code with password-protected VBAProject.

Sub UnprotecPassword()

Dim currentActiveWb As Workbook

Set  wb = ActiveWorkbook

If wb.VBProject.Protection <> 1 Then
    Exit Sub
End If

Set currentActiveWb = ActiveWorkbook

wb.Activate

SendKeys "%{F11}"
SendKeys "^r" ' Set focus to Explorer
SendKeys "{END}" ' Tab to locked project
SendKeys "~" ' Enter
SendKeys "pass"
SendKeys "~" ' Enter

If (wb.VBProject.Protection = vbext_pp_locked) Then
    MsgBox ("failed to unlock")
End If
currentActiveWb.Activate

End Sub

iincitr
  • 70
  • 1
  • 10
  • Just FYI, macro passwords are [not as secure](https://stackoverflow.com/questions/1026483/is-there-a-way-to-crack-the-password-on-an-excel-vba-project) as you would think – urdearboy Apr 07 '20 at 22:47
  • You would have to trust access to the VBAProject to do what you want, and the standard response is "don't do that". Maybe it would be helpful to explain why you are doing this so you don't get a bunch of people telling you not to. – HackSlash Apr 07 '20 at 22:57
  • Hi all. We developed a template and many workers use them with some code on it and especially Workbook_BeforeSave() and WorkBoook_Open() events. But now we have to change them for a bunch of populated workbooks. The change method is via a newly developed add-in. We can achieve it with no password-protected VBA. But with the password is not. – iincitr Apr 07 '20 at 23:09

1 Answers1

0

Since I know the password of the password-protected VBA modules, just export to all modules as .Bas and .CLS, and SaveAs original *.XLSM as *.XLSX and import all the exported module on *.XLSX and again SaveAs *.xlsm.

ActiveWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule

That is workaround.

iincitr
  • 70
  • 1
  • 10