AutoClose Macro Continuation

B

Barb R.

I want a macro that will run if any changes have been made to the document
and the document is either saved or closed. The following seems to run only
on close, but not on save. The macro is stored within the document as
opposed to in a template. Is there something I need to change?

Sub AutoClose()
'
' AutoClose Macro
' Macro created 3/29/2005 by Barb Reinhardt
'
Dim lastMod

lastMod = ActiveDocument.CustomDocumentProperties("ModificationDate").Value

If ActiveDocument.Saved = False Then
If MsgBox("The document modification date is " & lastMod & _
". Do you want to change" & " the document modification date to
today's date?", vbYesNo) = vbYes Then
ActiveDocument.CustomDocumentProperties("ModificationDate").Value = Date
Selection.WholeStory
Selection.Fields.Update
ActiveDocument.Save

End If
End If

End Sub

Thanks for your continued support (reminds me of the old Bartles and Jaymes
ads)

Barb Reinhardt
 
J

Jay Freedman

Hi Barb,

This should work, although I haven't actually tried it:

Make another copy of the AutoClose macro. Change its name to FileSave.
That will cause it to intercept the File > Save command (including the
Ctrl+S shortcut and the Save button on the toolbar). Then modify the
code in one place: Move the statement ActiveDocument.Save between the
two End If statements, so the save will occur even if the modification
date doesn't change.
 
B

Barb R.

Ler me make sure I understand what you said:

Should I move the ActiveDocument.Save statement between the two End If
statements for the FileSave macro only?
 
J

Jay Freedman

Yes, that's right, only in the FileSave macro -- but I think I need to
amend my instruction.

For the AutoClose macro, you don't want to run the Save statement
explicitly if the mod-date wasn't changed. You just want the ordinary
closing action, which will display the "save changes?" message box if
the document has any unsaved changes, or will just close the document
if it's clean.

The amendment is this (again, I haven't tried to run your code): If
your AutoClose macro runs and the document stays open, you need to put
the statement
ActiveDocument.Close wdDoNotSaveChanges
just before the End Sub statement. (This one does not go in the
FileSave macro.)
 
B

Barb R.

I'm not sure I agree. There are often edits to the document for style only
and we want to know when a "real" change has been made to the substance of
the document as opposed to "style" and "format" changes.
 

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