Preventing Excel prompt from Word VBA -
i'm working vba on word , excel. have word running userform automatically open excel file. user should fill data in excel file , go word userform. when user finish filling fields in word userform, run vba code on word copy data excel word. after finished, excel file closed automatically. therefore, need prevent user closing excel app manually.
in order that, use these code in excel vba in sub workbook_beforeclose
. if user close excel application window, show message box ask whether user still working word userform. code follows:
private sub workbook_beforeclose(cancel boolean) answer = msgbox("are still working word userform?", vbyesno) if answer = vbyes cancel = true msgbox "this workbook should not closed. automatically closed when finish working ms. word template userform." else application.thisworkbook.saved = true end if end sub
in word vba, have code close excel file:
sub closeexcelapp() if not excelapp nothing excelapp.displayalerts = false excelwb.close savechanges:=false set excelwb = nothing excelapp.quit end if set excelapp = nothing end sub
this sub called when word vba code done copying data excel word. however, calling sub cause workbook_beforeclose
called. meanwhile, don't want workbook_beforeclose
called when call closeexcelapp
sub word vba.
any suggestion?
you can disable events:
sub closeexcelapp() if not excelapp nothing excelapp.displayalerts = false excelapp.enableevents = false excelwb.close savechanges:=false set excelwb = nothing excelapp.quit end if set excelapp = nothing end sub
Comments
Post a Comment