excel - Findwindow does not work in 64bit VBA7 -


the code presented @ unlocking password protected vba project works under 32 not 64bit. specifically,

ret = findwindow(vbnullstring, "vbaproject password") 

always return 0. have tried

ret = findwindow("#32770", "vbaproject password")  ret = findwindow("xlmain", "vbaproject password") 

none works. have tried following apis: setforegroundwindow, bringwindowtotop, setfocus, getactivewindow, getwindowthreadprocessid. still failed don't think it's focus issue. perhaps it's timing? tried using

settimer 

but new apis not sure how implement that.

i calling via workbookopen app event inside personal.xlsb trying fill in password upon opening workbook.

private sub appevent_workbookopen(byval wb excel.workbook)  if wb.vbproject.protection <> 1 exit sub end if  call unlockvba(wb)  end sub 

edit: have set declarations ptrsafe , longptr applicable.

figured out. issue wasn't 64bit, timing/focus issue.

sub unlockvba(wb)  if wb.name = "personal.xlsb" exit sub  application.vbe.mainwindow.visible = true  timerid = settimer(0&, 0&, 500&, addressof timerproc)  application.vbe.commandbars(1).findcontrol(id:=2578, recursive:=true).execute  end sub  public sub timerproc(byval hwnd longptr, byval wmsg longptr, byval idevent longptr, byval dwtime longptr)  on error resume next killtimer hwnd, timerid  mypassword = "password"  ret = findwindow(vbnullstring, "vbaproject password") childret = findwindowex(ret, byval 0&, "edit", vbnullstring) if childret <> 0 call sendmessage(childret, wm_settext, false, byval mypassword) doevents end if  childret = findwindowex(ret, byval 0&, "button", vbnullstring)  if childret <> 0 'msgbox "button's window found"  '~~> caption of child window strbuff = string(getwindowtextlength(childret) + 1, chr(0)) getwindowtext childret, strbuff, len(strbuff) butcap = strbuff  '~~> loop through child windows while childret <> 0     '~~> check if caption has word "ok"     if instr(1, butcap, "ok")     '~~> if button looking exit     openret = childret     exit     end if      '~~> handle of next child window     childret = findwindowex(ret, childret, "button", vbnullstring)     '~~> caption of child window     strbuff = string(getwindowtextlength(childret) + 1, chr(0))     getwindowtext childret, strbuff, len(strbuff)     butcap = strbuff loop  if openret <> 0 '~~> click ok button sendmessage childret, bm_click, 0, vbnullstring else msgbox "the handle of ok button not found" end if else msgbox "button's window not found" end if 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -