Macro to Determine If a Document Has Been Saved

Last reviewed: August 5, 1997
Article ID: Q119741
The information in this article applies to:
  • Microsoft Word for Windows, versions 6.0, 6.0a

SUMMARY

When writing Word for Windows macros, you may need to know whether or not the current document has been saved. The FileNameFromWindow$() function returns an empty string if the document hasn't been saved in Word 6.0 for Windows.

Word 6.0

Sub MAIN
If FileNameFromWindow$() = "" Then MsgBox "Document is not saved"
End Sub

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

The following Word 2.0 macro determines if the current document has been saved by checking the filename in the DocumentStatistics dialog box.

Word 2.0

Sub MAIN
Dim dlg As DocumentStatistics GetCurValues dlg file$ = dlg.FileName If Left$(file$, 8) = "Document" Then MsgBox "Document is not saved"
End Sub

The above macro example dimensions the DocumentStatistics dialog box and then retrieves the filename (file$ = dlg.FileName). If the first eight letters are "Document", a message box appears indicating that the document has not been saved.

REFERENCES

"Microsoft Word Developer's Kit," version 6.0, pages 89-90

Kbcategory: kbusage kbmacro KBSubcategory:


Additional reference words: 6.0 6.0a Saved FileSave Macro word6
DocumentStatistics Save FileSaveAs winword how basic
Version : 6.0 6.0a
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 5, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.