ms word - Can't Close and Delete Open MSWord 2010 Document (ActiveDocument.Close prevents Kill command from running.) -
i'm trying close open word document , delete part of documentbeforeclose event. keep running across following code in searches (+/- error trapping statements):
dim killfile string killfile = dir$(activedocument.fullname) if len(dir$(killfile)) > 0 setattr killfile, vbnormal activedocument.close false kill killfile end if i've found similar code (well, frankly identical code) in several places, , seems confirm works, cannot run correctly in own attempts, regardless of module have code in. when run, document closes, code stops there , never gets kill command. in theory instance of word supposed keep running script once document closes; in case instance open, there's nothing running anymore @ point. doing wrong here?
if it's helpful, in version of code i'm working have while loop going through directory , deleting documents containing "temp.doc" in name. code has no trouble running through , deleting closed files, not delete active/open document after closing.
is need place in normal module in order work? (would reeeaally avoid if possible). help!
editing add top few relevant search results googling "msword vba delete open document":
- http://word.tips.net/t001346_deleting_the_open_document_file.html
- http://geekgirls.com/2010/02/deleting-an-open-document-in-microsoft-word/
- delete doc when macro finishes
again, unifying factor appears be:
activedocument.close kill whateveropenfile ...which plain doesn't seem make sense.
Comments
Post a Comment