Hello Peter,
From your post, my understanding on this issue is: you want to know how to
distinguish the user's save from Word AutoSave in DocuemntBeforeSave event
handler. If I'm off base, please feel free to let me know.
As we see, DocumentBeforeSave event fires on background auto save. The
reason why this happens is because the application is not able to
differentiate between saving a document by the AutoRecovery option or
saving the document using the File->Save menu option. This is by design in
the application. According to our internal logs for the issue, there
doesn't seem to be a way to detect AutoSave. But here are several
workarounds you may have a try to see if they fit your current situation:
Workaround #1. Overriding FileSave (Recommended)
If what you need is to trap the case when the user clicks Save or SaveAs,
you may consider using the FileSave and FileSaveAs override in a document
template instead, a way simpler and cleaner than setting up event handler.
The following articles discuss the usage of these two macros:
http://msdn2.microsoft.com/en-us/library/Aa264128(office.10).aspx
http://support.microsoft.com/default.aspx?scid=kb;en-us;211468
For example:
To intercept each call and set a parameter or global variable.
Sub FileSave()
DoMySave "FileSave"
End Sub
Sub FileSaveAs()
DoMySave "FileSaveAs"
End Sub
But the problem of this workaround is that it may require us to deploy the
add-in with the template macros.
Workaround #2. Disabling AutoSave
We can turn off AutoSave, but this is application-wide, which means it
could be very dangerous for the user if he's working on multiple documents.
Therefore, this is not a recommended approach.
Workaround #3. Using SaveAsUI parameter in BeforeSaveHandler:
private void BeforeSaveHandler(Word.Document Doc, ref bool SaveAsUI, ref
bool Cancel)
You may try to encapsulate all of the code in the BeforeSaveHandler with
if(SaveAsUI)
{ ... }
The parameter SaveAsUI is used to indicate whether we need to display the
Save As dialog box. And generally, in AutoSave, the parameter is set to
FALSE. But the problem is that, if the document has already been saved and
it is not 'SaveAs', the flag SaveAsUI will also be false because no 'Save'
dialog box is displayed.
Please let me know if you have any other concerns, or need anything else.
Sincerely,
Jialiang Ge (
[email protected], remove 'online.')
Microsoft Online Community Support
==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document:
http://blogs.msdn.com/msdnts/pages/postingAlias.aspx
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.