Word VBA - DocumentBeforeSave event? -
i using following vba code make message box appear while saving word document,
public withevents appword word.application private sub appword_documentbeforesave _ (byval doc document, _ saveasui boolean, _ cancel boolean) dim intresponse integer intresponse = msgbox("do want " _ & "save document?", _ vbyesno) if intresponse = vbno cancel = true end sub
this code written in class. not work. nothing happens when saving. issue here?
i made work. analystcave.com help. did:
i create new class named eventclassmodule , copied following code,
public withevents app word.application private sub app_documentbeforesave _ (byval doc document, _ saveasui boolean, _ cancel boolean) dim intresponse integer intresponse = msgbox("do want " _ & "save document?", _ vbyesno) if intresponse = vbno cancel = true end sub
then created module named mdleventconnect , copied following code,
dim x new eventclassmodule sub register_event_handler() set x.app = word.application end sub
after on thisdocument copied following code,
private sub document_new() register_event_handler end sub private sub document_open() register_event_handler end sub
saved document , re-opened it. when try save document executed documentbeforesave event perfectly.
Comments
Post a Comment