The code presented at Unlocking Password Protected VBA project works under 32 but not 64bit. Specifically,
Ret = FindWindow(vbNullString, "VBAProject Password")
always return 0. I have tried
Ret = FindWindow("#32770", "VBAProject Password")
Ret = FindWindow("XLMAIN", "VBAProject Password")
None works. I have also tried the following APIs: setforegroundwindow, bringwindowtotop, setfocus, getactivewindow, getwindowthreadprocessid. Still failed so I don't think it's a focus issue. Perhaps it's timing? I tried using
SetTimer
but I am new to APIs so not sure how to implement that.
I am calling this via the workbookopen app event inside my personal.xlsb I am trying to fill in password upon opening any workbook.
Private Sub AppEvent_WorkbookOpen(ByVal wb As Excel.Workbook)
If wb.VBProject.Protection <> 1 Then
Exit Sub
End If
Call unlockvba(wb)
End Sub
Edit: I have set my declarations to PtrSafe and LongPtr where applicable.