How can I tell if my file has been saved already?

R

RuthS

I have a template, with fill-in form fields. I have a working macro to
'SaveAs' the document as it exits a particular form field. But I want to
execute the SaveAs macro only if it's a new document and has not been saved
before.

Is there a way to set up an if statement to tell if the file is new or has
been saved already?

Thanks, Ruth
 
G

Greg Maxey

Ruth,

A file that has never been saved has no file path (or a zero length path) so
I do it like this.

Sub SaveTest()
If Not ActiveDocument.Saved Then
If Len(ActiveDocument.Path) = 0 Then
MsgBox "This file has never been saved."
Else
If MsgBox("This file has been changed since" _
& " last save. Do you want to save it" _
& " now", vbYesNo, "Changes Not Saved") = vbYes Then
ActiveDocument.Save
End If
End If
End If
End Sub

As file that has never been saved has no path name.
 
R

RuthS

Thank you Greg. That was really helpful. Ruth

Greg Maxey said:
Ruth,

A file that has never been saved has no file path (or a zero length path) so
I do it like this.

Sub SaveTest()
If Not ActiveDocument.Saved Then
If Len(ActiveDocument.Path) = 0 Then
MsgBox "This file has never been saved."
Else
If MsgBox("This file has been changed since" _
& " last save. Do you want to save it" _
& " now", vbYesNo, "Changes Not Saved") = vbYes Then
ActiveDocument.Save
End If
End If
End If
End Sub

As file that has never been saved has no path name.


--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
 

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