Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2005

Tip: Looking for answers? Try searching our database.

AutoClose Macro Continuation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Barb R. - 29 Mar 2005 17:43 GMT
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
Jay Freedman - 29 Mar 2005 19:43 GMT
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.

--
Regards,
Jay Freedman
Microsoft Word MVP         FAQ: http://word.mvps.org

>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
[quoted text clipped - 28 lines]
>
>Barb Reinhardt
Barb R. - 29 Mar 2005 20:51 GMT
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?

> Hi Barb,
>
[quoted text clipped - 44 lines]
> >
> >Barb Reinhardt
Jay Freedman - 30 Mar 2005 01:35 GMT
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.)

--
Regards,
Jay Freedman
Microsoft Word MVP         FAQ: http://word.mvps.org

>Ler me make sure I understand what you said:
>
[quoted text clipped - 49 lines]
>> >
>> >Barb Reinhardt
Barb R. - 30 Mar 2005 15:23 GMT
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.

> Yes, that's right, only in the FileSave macro -- but I think I need to
> amend my instruction.
[quoted text clipped - 70 lines]
> >> >
> >> >Barb Reinhardt
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.