Link to home
Start Free TrialLog in
Avatar of thenelson
thenelson

asked on

rename the active document in MS word

How do I rename the active document in MS word using VBA (macros)? I want to save the document with the new name and delete the old name.  TIA
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

You can only change the name by saving it, so you need something like:

ActiveDocument SAveas ActiveDocument.Path & "\" & "NewName.doc"
Avatar of thenelson
thenelson

ASKER

So I saved the filed under the new name. But now I need to delete the old file. I tried using
   Set fs = CreateObject("Scripting.FileSystemObject")
   fs.DeleteFile TheFileName
but I get "Access denied". Ms Word still has it open so it can't be deleted.

So how do I delete the old file?
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
When the code gets to
    Kill strFullName
I get "permission denied"

This works for me
    ActiveDocument.Close wdSaveChanges
    Name strFullName As Replace (strFullName, ".doc", " Signed.doc")
Thanks for your help!