Check to see if excel file has been saved

G

Guest

How do you check if an excel file has been saved in VBA? That is, if I have
an excel file open, what property tells me if the file has been saved yet?

I am thinking of an instance where I open a new workbook and forget to save
it. I want to run a macro that tells me that although the file is open, it
has not been saved yet.

Thanks
 
M

Mike Fogleman

From VBA Help for "Saved":

Saved Property Example

This example displays a message if the active workbook contains unsaved
changes.

If Not ActiveWorkbook.Saved Then
MsgBox "This workbook contains unsaved changes."
End IfThis example closes the workbook that contains the example code and
discards any changes to the workbook by setting the Saved property to True.

ThisWorkbook.Saved = True
ThisWorkbook.CloseMike F"ExcelMonkey"
 

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