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 / August 2006

Tip: Looking for answers? Try searching our database.

How to determine if document was changed at all?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kees - 23 Aug 2006 15:15 GMT
I need to determine if, after opening, a document is changed just before the
dosument is printed. It is NOT a new document.
I use the "documentbeforeprint" event but then need to detemine if any
changes are made, if so I have to change a date and editor field in the
document as the document isn't the original document anymore.

Can this be done? How?

Regards, Kees.
Helmut Weber - 23 Aug 2006 15:46 GMT
Hi Kees,

as long as a document wasn't changed,
this returns true:

MsgBox ActiveDocument.Saved

There maybe limits, though,
e.g. if two changes result in exactly the same text,
and of course, if there is some kind of document automation,
fields update etc.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Greg Maxey - 23 Aug 2006 16:04 GMT
Helmut,

I almost posted something similiar but then thought the OP might be
looking for something to indicate whether the document was changed
since being opened rather than changed since last being saved.  In the
latter case, our suggestion falls short.

I didn't have time to work it out, but it seems he would need to
intercept both the save and save as events, write a document variable
to record the new modified date, compare that to the modified date at
the time the document was opened (put in another variable during an
AutoOpen macro) then if the two variables differrred and .Saved
returned false he could proceed accordingly.

Perhaps you or someone else has already worked something like this out.

> Hi Kees,
>
[quoted text clipped - 15 lines]
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"
Jonathan West - 23 Aug 2006 16:13 GMT
> Helmut,
>
[quoted text clipped - 11 lines]
>
> Perhaps you or someone else has already worked something like this out.

It would be a matter of writing an event handler for the
Application_DocumentBeforeSave() event. That would deal with both the Save
and Save As cases.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

Greg Maxey - 23 Aug 2006 17:09 GMT
Jonathan,

I have never messed with this sort of thing.  I went in help and put
together the following code, but it doesn't seem to work.  Can you
advise on what I am missing or doing wrong.  Thanks.

This code is in a module in the Document Project:

Sub AutoOpen()
Dim X As New EventsClassModule
 Set X.appWord = Word.Application
End Sub

This code is in a Class module name EventsClassModule

Option Explicit
Public WithEvents appWord As Word.Application
Private Sub appWord_DocumentBeforeSave _
       (ByVal Doc As Document, _
       SaveAsUI As Boolean, _
       Cancel As Boolean)
Dim intResponse As Integer
intResponse = MsgBox("Do you really want to " _
 & "save the document?", vbYesNo)
If intResponse = vbNo Then Cancel = True
End Sub

Nothing happens when I open the document and then save it.

> > Helmut,
> >
[quoted text clipped - 22 lines]
> Please reply to the newsgroup
> Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
Kees - 24 Aug 2006 09:32 GMT
Greg,

This should work as I have similar code to trap both beforeprint and
beforesave, the one thing people tend to forget that after you typed this in
you have to execute the macro that defines your classmodule, in your case
AutoOpen(), or close and open the doc and then test it.  Just writing the
code is not sufficient.

Regards, Kees.

> Jonathan,
>
[quoted text clipped - 51 lines]
> > Please reply to the newsgroup
> > Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
Greg Maxey - 24 Aug 2006 11:40 GMT
Kees,

Yep, I sorted that out with the help of Jezebel in a separate post.  Glad
your problem is solved.

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Greg,
>
[quoted text clipped - 65 lines]
>> > Please reply to the newsgroup
>> > Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
Kees - 23 Aug 2006 16:23 GMT
Greg,

Indeed, I just tested the variable when nothing was changed and it was false
also. Now that's not exactly what I wanted. I sort of assumed that the
variable would be true right after opening as the original "saved" doc still
exists and as soon as I changed something this would turn false. Sort of
"dirty" flag.

Regards, Kees.

> Helmut,
>
[quoted text clipped - 31 lines]
> > Win XP, Office 2003
> > "red.sys" & Chr$(64) & "t-online.de"
Greg Maxey - 23 Aug 2006 16:30 GMT
Kees,

I didn't have time to extensively test, but try this combination:

Sub AutoOpen()
ActiveDocument.Variables("SavedDate").Value =
ActiveDocument.BuiltInDocumentProperties(wdPropertyTimeLastSaved)
ActiveDocument.Saved = True
End Sub

Sub ScratchMacro()
If ActiveDocument.Variables("SavedDate").Value <> _
 ActiveDocument.BuiltInDocumentProperties(wdPropertyTimeLastSaved)
Then
 MsgBox "This document was saved or changed since it was opened."
End If
If Not ActiveDocument.Saved Then
 MsgBox "This document was saved or changed since it was opened."
End If
End Sub

> Greg,
>
[quoted text clipped - 41 lines]
> > > Win XP, Office 2003
> > > "red.sys" & Chr$(64) & "t-online.de"
Kees - 24 Aug 2006 09:23 GMT
Greg, Helmut,

Thank you for your assistance Gregs' code seems to do the job twofold.

First, by setting the activedocument.saved to true any change would toggle
this to false.
Second, when the document was saved before printed, the code comparing the
"savedates" will detect this and I could act accordingly.

Thanks again,  Kees.

> Kees,
>
[quoted text clipped - 62 lines]
> > > > Win XP, Office 2003
> > > > "red.sys" & Chr$(64) & "t-online.de"
Helmut Weber - 23 Aug 2006 16:28 GMT
Hi Greg,

you are right.

Yes, in a way I was lucky with helping,
by a useless answer, at second thought.

I had that case in the German groups lately,
where someone wanted to place the cursor
at the start of the doc before closing it,
in order to have the cursor there when opening it.
I recommended
activedocument.range(0,0).select
in autoclose,
which made the OP happy,
and left me rather embarrassed. ;-)

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Greg Maxey - 23 Aug 2006 16:35 GMT
Helmut,

LOL.  I suppose a disadvantage that infrequent users have using the
@discussions.com address is that we can't reach out to them and correct
our mistakes ;-).  I see that Kees is back and I think on the right
track now.

> Hi Greg,
>
[quoted text clipped - 20 lines]
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"
Kees - 23 Aug 2006 16:06 GMT
Helmut,

Soooooo easy, now I think of it.    I implemented it and indeed did want I
wanted!
Vielen dank.

Kees.

> Hi Kees,
>
[quoted text clipped - 7 lines]
> and of course, if there is some kind of document automation,
> fields update etc.
Greg Maxey - 23 Aug 2006 16:22 GMT
Helmut,

Perhaps this would do the trick:

Sub AutoOpen()
ActiveDocument.Variables("SavedDate").Value =
ActiveDocument.BuiltInDocumentProperties(wdPropertyTimeLastSaved)
ActiveDocument.Saved = True
End Sub
Sub ScratchMacro()
If ActiveDocument.Variables("SavedDate").Value <> _
 ActiveDocument.BuiltInDocumentProperties(wdPropertyTimeLastSaved)
Then
 MsgBox "This document was saved or changed since it was opened"
End If
If Not ActiveDocument.Saved Then
 MsgBox "This document was saved or changed since it was opened"
End If
End Sub

> Hi Kees,
>
[quoted text clipped - 15 lines]
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"
 
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.