Saving a document as and automatically deleting the original

W

weetabx

Hello, people.

Is there a macro that could help me do the following:

I am working on a document named ABC that I have already saved on my
disk and want to save it with a different name, XYZ, while at the same
time getting rid of the ABC document stored on my disk, without having
to delete it by getting to its containing folder using Windows
Explorer.

Any ideas?

Regards,

Wtbx
 
T

Tammy

Hi Wtbx,

This should provide what you're after - you'll just need to change the
strOldDoc and strNewDoc variable to your documents' names.

Dim strOldDoc As String
Dim strNewDoc As String

strOldDoc = "c:\userdata\test document.doc" 'Existing document
name
strNewDoc = "c:\userdata\new test document.doc" 'New document name

'Renames old document to new document
Name strOldDoc As strNewDoc

Cheers,
Tammy
 
W

weetabx

Thanx for the help Tammy.

The problem was that the Name command does not work when the document
is open (as I found out reading the help file) plus i didn't want to
hardcode the filenames. But having been given the basics by you and
with a little google search in newsgroups, I managed to change the
code pasting different things from different macros I found online and
by a long process of trial and error. Here it is:

Sub Rename()

Dim OldName, NewName
OldName = ActiveDocument.Name: NewName = InputBox("Supply file name",
"Rename", OldName)
If NewName = "" Then
End
End If
ActiveDocument.Close
Name OldName As NewName
Documents.Open NewName

End Sub

It's funny it works because I have no experience in writing code, and
I can't help fearing that at some point it will crash and destroy the
document I will be working on at the moment.

Regards,

Wtbx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top