Can't KILL file using Word 2007 VBA if it's DOC format -
the following code works docx files, gives "access denied" on doc files:
public sub savegraded() oldnamepath = activedocument.fullname oldname = getfilename(activedocument.name) oldextension = getextension(activedocument.fullname) newname = oldname & "_graded" & "." & oldextension activedocument.saveas filename:=newname kill oldnamepath end sub
indeed, it's 1 of weird things word, it'll hold .doc file open exclusively longer .docx.
you can use loop continually test delete until works - don't use kill since can't trap it, use vbscript filesystemobject.deletefile (str name, bool force), more reliable anyway - or can use activedocument.close , reopen it. i've noticed doesn't work , have follow application.quit; goodbye script execution unless you're automating external application, do.
Comments
Post a Comment