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

Re: How can I tell if my file has been saved already? by Greg

Greg
Wed Aug 09 18:51:04 CDT 2006

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.


RuthS wrote:
> 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



Re: How can I tell if my file has been saved already? by RuthS

RuthS
Thu Aug 10 14:10:04 CDT 2006

Thank you Greg. That was really helpful. Ruth

"Greg Maxey" wrote:

> 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.
>
>
> RuthS wrote:
> > 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
>
>
>