PDA

View Full Version : Toggling "Document has been changed"



MWE
03-11-2006, 05:44 PM
When changes are made to a Word doucment using VBA, the document's internal property that keeps track of its "changed status" is not updated. Thus you can make lots of changes via VBA and the document does not know it should ask about saving during the close operation.

So, how do I tell the document that it has changed and it should ask me about Saving when it closes? I have found some interesting document properties in the object browser, but not the desired one.

Thanks

TonyJollans
03-11-2006, 06:10 PM
The property you want is Document.Saved but I don't know of any circumstances where Word doesn't set it - whether changes are made in code or not - can you give me precise details of what you are doing?

MWE
03-11-2006, 07:00 PM
The property you want is Document.Saved but I don't know of any circumstances where Word doesn't set it - whether changes are made in code or not - can you give me precise details of what you are doing?
Sure. In my other thread about tables and page numbers, VBA code looks through the document for certain keywords and if found builds a table of stuff. If I close the document after the build, Word does not ask me if I want to save it. This VBA library does lots of things to the target document, but the document does not seem to "know" that and never asks to be saved at closed.

My "version" of VBA (Office 2k) seems to have some strange quirks, e.g., the way the editor works, exploding Help utility, ... so maybe this is one more anomoly. :dunno

fumei
03-12-2006, 09:40 PM
Really? I have never heard of Word not being able to know that a whole table, and text has been added to a document. I am finding that hard to believe. I have never had VBA make changes to a document, and Word not know that. I mean, even if you have VBA add a single space, then use the close button Word will ask if you want to save changes.

Are you sure there is no save in your code?

MWE
03-12-2006, 10:15 PM
Really? I have never heard of Word not being able to know that a whole table, and text has been added to a document. I am finding that hard to believe. I have never had VBA make changes to a document, and Word not know that. I mean, even if you have VBA add a single space, then use the close button Word will ask if you want to save changes.

Are you sure there is no save in your code?
It may be the way I am "adding" the table. If the VBA detects that the table is already there (with older data), it will delete all except the top few rows and add new rows with updated data.

There is no save statement anywhere in the code being used.

I have run some tests to see what I have "before" and after. Unless I explicitly save the file, the file is not saved and any changes made by VBA are lost.

TonyJollans
03-13-2006, 01:18 AM
Any chance you can post a document exhibiting the problem

MWE
03-13-2006, 05:22 AM
Any chance you can post a document exhibiting the problem
Its not any document, its all documents

TonyJollans
03-13-2006, 07:45 AM
This sounds an awful lot some sort of corruption.

Did the Document.Saved property help at all - does it get set?

fumei
03-14-2006, 12:17 AM
Well something is wonky here. I just ran 50 tests of VBA making changes to various documents, in various ways. From tables to text, from properties to formfields. In every single case, Word noted that there had been changes made.

Your statement that VBA changes are not detected by Word may be true for you, but I have never seen it. And it certainly is not true for me.

Something is not correct here.