none
Application_DocumentBeforeSave - Performing a SaveAs, How to delete original file? RRS feed

  • Question

  • I am using vs2010 & Office2010

    This is just a snippet from my code. In the full version, there is logic determining
    if the file name needs to be changed. Word appears to hang on to the original file
    even after it has been renamed.

    Thanks in advance,
    Tim

    System.IO.IOException:
    The process cannot access the file 'Original File' because it is being used by another process.

    Private Sub Application_DocumentBeforeSave(ByVal Doc
        As Microsoft.Office.Interop.Word.Document,
        ByRef SaveAsUI As Boolean, ByRef Cancel As Boolean) 
        Handles Application.DocumentBeforeSave
      Dim OrigFName As String = Doc.FullName
      Doc.SaveAs(FileName:=Doc.Path & "\zzz",
        FileFormat:=Word.WdSaveFormat.wdFormatDocument)
      System.IO.File.Delete(OrigFName)     'Throws Exception
    End Sub


    Tim

    Wednesday, February 22, 2012 4:01 PM

Answers

  • Hello,

    You need to do this after DocumentBeforeSave is completed: cancel DocumentBeforeSave, start a System.Windows.Forms.Timer and delete the file in the timer's event.

    Note that DocumentBeforeSave can be invoked by AutoSave. You can determine this scenario by checking if WordApp.WordBasic.IsAutosaveEvent is true. The code below is taken from this page:

    object oBasic = Application.WordBasic;
     // this is where we invoke the object and
     // get the property. But we get an "object" 
    // back so be careful casting it.
     object fIsAutoSave = 
        oBasic.GetType().InvokeMember(
             "IsAutosaveEvent", 
            BindingFlags.GetProperty, 
            null, oBasic, null);
     
    if (int.Parse(fIsAutoSave.ToString()) == 1)
         MessageBox.Show("Is AutoSave");
     else
         MessageBox.Show("Is regular save");
    
    Hope this helps.

    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader

    Please mark answers and useful posts to help other developers use the forums efficiently.

    • Marked as answer by Tim_Shaf Wednesday, February 22, 2012 6:19 PM
    Wednesday, February 22, 2012 4:31 PM
  • Andrei,

    Appears that when the new document is unloaded, it releases the lock
    on the original document.

    Option 1 uses Doc.SaveAs, Doc.Close, deletes origFName, and starts a timer
      to load the newFName
    Option 2 use Doc.Close(wdSaveChanges), deletes newFName if exists,
      renames origFName to newFName, and starts a timer
      to load the newFName

    In both cases opening the newFName within the DocumentBeforeSave handler
      causes Word to crash after multiple cycles

    I am leaning towards Option 2. Any comments?

    Appreciate your help,
    Tim

    'Option 1: Using Doc.SaveAs
    Private Sub Application_DocumentBeforeSave(ByVal Doc As Microsoft.Office.Interop.Word.Document,
        ByRef SaveAsUI As Boolean, ByRef Cancel As Boolean) Handles Application.DocumentBeforeSave
      Dim WordApp As Word.Application = Doc.Application
      If Not WordApp.WordBasic.IsAutoSaveEvent Then
        Dim newFName As String = Doc.Path & "\bbb" & Now.ToString("yyMMddHHmmss") & ".doc"
        Dim origFName As String = Doc.FullName
        Dim SaveOption As Boolean = WordApp.Options.BackgroundSave
        WordApp.Options.BackgroundSave = False
        Doc.SaveAs(FileName:=newFName,
          FileFormat:=Word.WdSaveFormat.wdFormatDocument)
        Doc.Close(SaveChanges:=Word.WdSaveOptions.wdDoNotSaveChanges)
        WordApp.Options.BackgroundSave = SaveOption
        Try
          System.IO.File.Delete(origFName)
        Catch ex As Exception
          MsgBox("Error deleting '" & System.IO.Path.GetFileName(origFName) & vbCrLf &
            ex.Message)
        End Try
        FileToOpen = newFName
        FileToOpenTimer.Start()
        'WordApp.Documents.Open(FileName:=newFName)    'Crashes Word after multiple cycles
        Cancel = True
      End If
    End Sub
    
    'Option 2: Using Doc.Close(SaveChanges) & renaming file
    Private Sub Application_DocumentBeforeSave(ByVal Doc As Microsoft.Office.Interop.Word.Document,
        ByRef SaveAsUI As Boolean, ByRef Cancel As Boolean) Handles Application.DocumentBeforeSave
      Dim WordApp As Word.Application = Doc.Application
      If Not WordApp.WordBasic.IsAutoSaveEvent Then
        Dim newFName As String = Doc.Path & "\bbb" & Now.ToString("yyMMddHHmmss") & ".doc"
        Dim origFName As String = Doc.FullName
        Dim SaveOption As Boolean = WordApp.Options.BackgroundSave
        WordApp.Options.BackgroundSave = False
        Doc.Close(SaveChanges:=Word.WdSaveOptions.wdSaveChanges)
        WordApp.Options.BackgroundSave = SaveOption
        Try
          If System.IO.File.Exists(newFName) Then _
            System.IO.File.Delete(newFName)
          System.IO.File.Move(sourceFileName:=origFName, destFileName:=newFName)
        Catch ex As Exception
          MsgBox("Error renaming '" & System.IO.Path.GetFileName(origFName) & vbCrLf &
            ex.Message)
        End Try
        FileToOpen = newFName
        FileToOpenTimer.Start()
        'WordApp.Documents.Open(FileName:=newFName)    'Crashes Word after multiple cycles
        Cancel = True
      End If
    End Sub
    
    Private FileToOpen As String = ""
    Private WithEvents FileToOpenTimer As New System.Windows.Forms.Timer() With {.Interval = 10}
    
    Private Sub FileToOpenEventProcessor(ByVal myObject As Object,
        ByVal myEventArgs As EventArgs) Handles FileToOpenTimer.Tick
      Try
        FileToOpenTimer.Stop()
        Application.Documents.Open(FileName:=FileToOpen)
      Catch ex As Exception
        MsgBox("Error Opening '" & System.IO.Path.GetFileName(FileToOpen) & vbCrLf &
          ex.Message)
      End Try
    End Sub


    Tim

    • Marked as answer by Tim_Shaf Friday, February 24, 2012 7:24 PM
    Thursday, February 23, 2012 3:15 PM

All replies

  • Hello,

    You need to do this after DocumentBeforeSave is completed: cancel DocumentBeforeSave, start a System.Windows.Forms.Timer and delete the file in the timer's event.

    Note that DocumentBeforeSave can be invoked by AutoSave. You can determine this scenario by checking if WordApp.WordBasic.IsAutosaveEvent is true. The code below is taken from this page:

    object oBasic = Application.WordBasic;
     // this is where we invoke the object and
     // get the property. But we get an "object" 
    // back so be careful casting it.
     object fIsAutoSave = 
        oBasic.GetType().InvokeMember(
             "IsAutosaveEvent", 
            BindingFlags.GetProperty, 
            null, oBasic, null);
     
    if (int.Parse(fIsAutoSave.ToString()) == 1)
         MessageBox.Show("Is AutoSave");
     else
         MessageBox.Show("Is regular save");
    
    Hope this helps.

    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader

    Please mark answers and useful posts to help other developers use the forums efficiently.

    • Marked as answer by Tim_Shaf Wednesday, February 22, 2012 6:19 PM
    Wednesday, February 22, 2012 4:31 PM
  • 1. Will Application.WordBasic.IsAutoSaveEvent provide the same information?

    2. Can you refer me to any examples about setting a timer
    during the DocumentBeforeSave to delete the file?

    Thanks


    Tim

    Wednesday, February 22, 2012 5:20 PM
  • 1. Sorry?

    2. No.


    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader

    Please mark answers and useful posts to help other developers use the forums efficiently.

    Wednesday, February 22, 2012 6:14 PM
  • Andrei,

    1. Just got thru testing Application.WordBasic.IsAutoSaveEvent and it works.
    2. Now working on a timer routine.

    Thanks for the help.


    Tim

    Wednesday, February 22, 2012 6:25 PM
  • 1. Added "Not Doc.Application.WordBasic.IsAutoSaveEvent " to avoid AutoSave.
    2. Added a timer set to a 30 second interval.

    Still getting System.IO.IOException:
    The process cannot access the file 'Original File' because it is being used by another process.

    Private Sub Application_DocumentBeforeSave(ByVal Doc As  
          Microsoft.Office.Interop.Word.Document,
          ByRef SaveAsUI As Boolean, ByRef Cancel As Boolean) Handles   Application.DocumentBeforeSave
      If Not Doc.Application.WordBasic.IsAutoSaveEvent Then
        Debug.Print(Now.ToString("MM/dd/yy HH:mm:ss"))
        FileToDelete = Doc.FullName
        FileToDeleteTimer.Start()
        Dim FName As String = Doc.FullName
        Debug.Print("Before:" & Doc.FullName)
        Doc.SaveAs(FileName:=Doc.Path & "\zzz" & Now.ToString("yyMMddHHmmss"),
          FileFormat:=Word.WdSaveFormat.wdFormatDocument)
        Debug.Print("After:" & Doc.FullName)
        Cancel = True
      End If
    End Sub

    Private FileToDelete As String = ""
    Private WithEvents FileToDeleteTimer As New System.Windows.Forms.Timer() With {.Interval = 30000}

    Private Sub FileToDeleteEventProcessor(ByVal myObject As Object,
        ByVal myEventArgs As EventArgs) Handles FileToDeleteTimer.Tick
      FileToDeleteTimer.Stop()
      Debug.Print("Timer expired " & Now.ToString("MM/dd/yy HH:mm:ss") & "," & FileToDelete)
      System.IO.File.Delete(FileToDelete)
      If Not System.IO.File.Exists(FileToDelete) Then
        Debug.Print("File deleted:" & FileToDelete)
      End If
    End Sub


    Tim

    Wednesday, February 22, 2012 8:04 PM
  • Try setting Application.Options.BackgroundSave = False before you call SaveAs and restoring the setting afterwards.

    Also, Word can lock the file if a large block is copied to the Clipboard; copy a couple of chars to the Clipboard to bypass this.


    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader

    Please mark answers and useful posts to help other developers use the forums efficiently.

    Wednesday, February 22, 2012 8:28 PM
  • The code below works fine for me in Word 2007. If the problem persists, I'll retest it inWord 2010 tomorrow.

    If Not WordApp.WordBasic.IsAutoSaveEvent Then
        Debug.Print(Now.ToString("MM/dd/yy HH:mm:ss"))
        FileToDelete = Doc.FullName
        Dim SaveOption As Boolean = WordApp.Options.BackgroundSave
        WordApp.Options.BackgroundSave = False
        'FileToDeleteTimer.Start()
        Debug.Print("Before:" & Doc.FullName)
        Doc.SaveAs(FileName:=Doc.Path & "\bbb", FileFormat:=Word.WdSaveFormat.wdFormatDocument)
        Debug.Print("After:" & Doc.FullName)
        Marshal.ReleaseComObject(Doc)
        WordApp.Options.BackgroundSave = SaveOption
        System.IO.File.Delete(FileToDelete)
        If Not System.IO.File.Exists(FileToDelete) Then
            Debug.Print("File deleted:" & FileToDelete)
        End If
        Cancel = True
    End If
    


    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader

    Please mark answers and useful posts to help other developers use the forums efficiently.

    Wednesday, February 22, 2012 9:18 PM
  • Andrei,

    I modified your latest code and performed some more testing.
    As shown by the "Debug Results", the original file (zzz120222131002.doc)
    is no longer loaded in Word, but there is some process that has it locked.

    Even after the routine has completed, I can't delete this file via Windows Explorer
    until I unload the SaveAs'd doc (bbb120222141208.doc) from Word.

    Truly appreciate all of your help.
    Tim


    Debug Results:
    02/22/12 14:12:08
    Before:C:\Data\Word14\TBS2\zzz120222131002.doc
    DocumentBeforeSave
    After:C:\Data\Word14\TBS2\bbb120222141208.doc
    A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll
    The process cannot access the file 'C:\Data\Word14\TBS2\zzz120222131002.doc' because it is being used by another process.
    DocumentBeforeSave - Open Files in Word
    bbb120222141208.doc
    Timer expired 02/22/12 14:12:38,C:\Data\Word14\TBS2\zzz120222131002.doc
    A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll
    The process cannot access the file 'C:\Data\Word14\TBS2\zzz120222131002.doc' because it is being used by another process.
    FileToDeleteEventProcessor - Open Files in Word
    bbb120222141208.doc

    Private Sub Application_DocumentBeforeSave(ByVal Doc As Microsoft.Office.Interop.Word.Document,
        ByRef SaveAsUI As Boolean, ByRef Cancel As Boolean) Handles Application.DocumentBeforeSave
      Dim WordApp As Word.Application = Doc.Application
      If Not WordApp.WordBasic.IsAutoSaveEvent Then
        Debug.Print(Now.ToString("MM/dd/yy HH:mm:ss"))
        FileToDelete = Doc.FullName
        FileToDeleteTimer.Start()
        Dim SaveOption As Boolean = WordApp.Options.BackgroundSave
        WordApp.Options.BackgroundSave = False
        Debug.Print("Before:" & Doc.FullName)
        Doc.SaveAs(FileName:=Doc.Path & "\bbb" & Now.ToString("yyMMddHHmmss"),
          FileFormat:=Word.WdSaveFormat.wdFormatDocument)
        Debug.Print("DocumentBeforeSave")
        Marshal.ReleaseComObject(Doc)
        WordApp.Options.BackgroundSave = SaveOption
        Debug.Print("After:" & Doc.FullName)
        Try
          System.IO.File.Delete(FileToDelete)
        Catch ex As Exception
          Debug.Print(ex.Message)
          Debug.Print("DocumentBeforeSave - Open Files in Word")
          For Each d As Word.Document In Application.Documents
            Debug.Print(d.Name)
          Next
        End Try
        If Not System.IO.File.Exists(FileToDelete) Then
          Debug.Print("File deleted:" & FileToDelete)
        End If
        Cancel = True
      End If
    End Sub
    
    Private FileToDelete As String = ""
    Private WithEvents FileToDeleteTimer As New System.Windows.Forms.Timer() With {.Interval = 30000}
    
    Private Sub FileToDeleteEventProcessor(ByVal myObject As Object,
        ByVal myEventArgs As EventArgs) Handles FileToDeleteTimer.Tick
      FileToDeleteTimer.Stop()
      Debug.Print("Timer expired " & Now.ToString("MM/dd/yy HH:mm:ss") & "," & FileToDelete)
      Try
        System.IO.File.Delete(FileToDelete)
      Catch ex As Exception
        Debug.Print(ex.Message)
        Debug.Print("FileToDeleteEventProcessor - Open Files in Word")
        For Each d As Word.Document In Application.Documents
          Debug.Print(d.Name)
        Next
      End Try
      If Not System.IO.File.Exists(FileToDelete) Then
        Debug.Print("File deleted:" & FileToDelete)
      End If
    End Sub

    Tim

    Wednesday, February 22, 2012 10:31 PM
  • Tim,

    Process Explorer says the file is locked by Word itself.

    The issue occurs if the original document or the target document or both of them are .doc files (WdSaveFormat.wdFormatDocument). This doesn't occur when both of them are .docx files (WdSaveFormat.wdFormatXMLDocument). At the moment I don't see any way out of the situation; googling doesn't help. I have a slim hope that a solution can be found in Description of how Word creates temporary files. Below is my current code (this is an Add-in Express based add-in, hope you can convert the code if required):

        Private Sub adxWordEvents_DocumentBeforeSave(ByVal sender As System.Object, ByVal e As AddinExpress.MSO.ADXHostBeforeSaveEventArgs) Handles adxWordEvents.DocumentBeforeSave
            If Not IsWorking Then Return
            Dim Doc As Microsoft.Office.Interop.Word.Document = e.HostObject
            If Not WordApp.WordBasic.IsAutoSaveEvent Then
                Debug.Print(Now.ToString("MM/dd/yy HH:mm:ss"))
                FileToDelete = Doc.FullName
    
                Dim SaveOption As Boolean = WordApp.Options.BackgroundSave
                WordApp.Options.BackgroundSave = False
    
                If adxRibbonCheckBoxClearClipboard.Pressed Then
                    Clipboard.Clear()
                End If
    
                Debug.Print("Before:" & Doc.FullName)
                Debug.Print("SaveAs:" & Me.AdxRibbonDropDown1.SelectedItemId)
                Doc.Save()
                If Me.AdxRibbonDropDown1.SelectedItemId = "idDOCX" Then
                    Doc.SaveAs(FileName:=Doc.Path & "\bbb", FileFormat:=Word.WdSaveFormat.wdFormatXMLDocument)
                Else
                    Doc.SaveAs(FileName:=Doc.Path & "\bbb", FileFormat:=Word.WdSaveFormat.wdFormatDocument)
                End If
                Debug.Print("After:" & Doc.FullName)
    
                If adxRibbonCheckBoxClearClipboard.Pressed Then
                    Clipboard.Clear()
                End If
    
                If Me.AdxRibbonCheckBoxReleaseDOC.Pressed Then
                    Dim qqq As Integer = Marshal.ReleaseComObject(Doc)
                    Debug.Print("ReleaseComObject returned " + qqq.ToString())
                    Doc = Nothing
                End If
    
                WordApp.Options.BackgroundSave = SaveOption
    
                Try
                    System.IO.File.Delete(FileToDelete)
                Catch ex As Exception
                    Debug.Print("File.Delete exception:" + ex.Message)
                End Try
    
                If Not System.IO.File.Exists(FileToDelete) Then
                    Debug.Print("File deleted:" & FileToDelete)
                Else
                    Debug.Print("File NOT deleted. Starting the timer...")
                    FileToDeleteTimer.Start()
                End If
    
                e.Cancel = True
            End If
        End Sub
    
        Private FileToDelete As String = ""
        Private WithEvents FileToDeleteTimer As New System.Windows.Forms.Timer() With {.Interval = 300}
    
        Private Sub FileToDeleteEventProcessor(ByVal myObject As Object, _
         ByVal myEventArgs As EventArgs) Handles FileToDeleteTimer.Tick
            FileToDeleteTimer.Stop()
            Debug.Print("Timer expired " & Now.ToString("MM/dd/yy HH:mm:ss") & "," & FileToDelete)
            Try
                System.IO.File.Delete(FileToDelete)
            Catch ex As Exception
                Debug.Print("File.Delete exception:" + ex.Message)
            End Try
    
            If Not System.IO.File.Exists(FileToDelete) Then
                Debug.Print("File deleted:" & FileToDelete)
            Else
                Debug.Print("File NOT deleted.")
            End If
        End Sub


    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader

    Please mark answers and useful posts to help other developers use the forums efficiently.

    Thursday, February 23, 2012 11:00 AM
  • Andrei,

    Thanks for the reply.

    If I read your explanation correctly, your new code will still have issues with files in .doc format. Please let me know if I misinterpreted your explanation. Currently the .doc format is one of my constraints.

    I reviewed  Description of how Word creates temporary files but did not come up with any other ideas.

    I remember a similar issue in Word 2003, so I am going to look thru my 2003 vba code to see how I handled it.

    Thanks for all your help.


    Tim

    Thursday, February 23, 2012 12:32 PM
  • > If I read your explanation correctly, your new code will still have issues with files in .doc format.

    Exactly. Alas.

    > I remember a similar issue in Word 2003, so I am going to look thru my 2003 vba code to see how I handled it.

    In case you have a solution, please (PLEASE!) publish it here.


    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader

    Please mark answers and useful posts to help other developers use the forums efficiently.

    Thursday, February 23, 2012 12:50 PM
  • Andrei,

    Appears that when the new document is unloaded, it releases the lock
    on the original document.

    Option 1 uses Doc.SaveAs, Doc.Close, deletes origFName, and starts a timer
      to load the newFName
    Option 2 use Doc.Close(wdSaveChanges), deletes newFName if exists,
      renames origFName to newFName, and starts a timer
      to load the newFName

    In both cases opening the newFName within the DocumentBeforeSave handler
      causes Word to crash after multiple cycles

    I am leaning towards Option 2. Any comments?

    Appreciate your help,
    Tim

    'Option 1: Using Doc.SaveAs
    Private Sub Application_DocumentBeforeSave(ByVal Doc As Microsoft.Office.Interop.Word.Document,
        ByRef SaveAsUI As Boolean, ByRef Cancel As Boolean) Handles Application.DocumentBeforeSave
      Dim WordApp As Word.Application = Doc.Application
      If Not WordApp.WordBasic.IsAutoSaveEvent Then
        Dim newFName As String = Doc.Path & "\bbb" & Now.ToString("yyMMddHHmmss") & ".doc"
        Dim origFName As String = Doc.FullName
        Dim SaveOption As Boolean = WordApp.Options.BackgroundSave
        WordApp.Options.BackgroundSave = False
        Doc.SaveAs(FileName:=newFName,
          FileFormat:=Word.WdSaveFormat.wdFormatDocument)
        Doc.Close(SaveChanges:=Word.WdSaveOptions.wdDoNotSaveChanges)
        WordApp.Options.BackgroundSave = SaveOption
        Try
          System.IO.File.Delete(origFName)
        Catch ex As Exception
          MsgBox("Error deleting '" & System.IO.Path.GetFileName(origFName) & vbCrLf &
            ex.Message)
        End Try
        FileToOpen = newFName
        FileToOpenTimer.Start()
        'WordApp.Documents.Open(FileName:=newFName)    'Crashes Word after multiple cycles
        Cancel = True
      End If
    End Sub
    
    'Option 2: Using Doc.Close(SaveChanges) & renaming file
    Private Sub Application_DocumentBeforeSave(ByVal Doc As Microsoft.Office.Interop.Word.Document,
        ByRef SaveAsUI As Boolean, ByRef Cancel As Boolean) Handles Application.DocumentBeforeSave
      Dim WordApp As Word.Application = Doc.Application
      If Not WordApp.WordBasic.IsAutoSaveEvent Then
        Dim newFName As String = Doc.Path & "\bbb" & Now.ToString("yyMMddHHmmss") & ".doc"
        Dim origFName As String = Doc.FullName
        Dim SaveOption As Boolean = WordApp.Options.BackgroundSave
        WordApp.Options.BackgroundSave = False
        Doc.Close(SaveChanges:=Word.WdSaveOptions.wdSaveChanges)
        WordApp.Options.BackgroundSave = SaveOption
        Try
          If System.IO.File.Exists(newFName) Then _
            System.IO.File.Delete(newFName)
          System.IO.File.Move(sourceFileName:=origFName, destFileName:=newFName)
        Catch ex As Exception
          MsgBox("Error renaming '" & System.IO.Path.GetFileName(origFName) & vbCrLf &
            ex.Message)
        End Try
        FileToOpen = newFName
        FileToOpenTimer.Start()
        'WordApp.Documents.Open(FileName:=newFName)    'Crashes Word after multiple cycles
        Cancel = True
      End If
    End Sub
    
    Private FileToOpen As String = ""
    Private WithEvents FileToOpenTimer As New System.Windows.Forms.Timer() With {.Interval = 10}
    
    Private Sub FileToOpenEventProcessor(ByVal myObject As Object,
        ByVal myEventArgs As EventArgs) Handles FileToOpenTimer.Tick
      Try
        FileToOpenTimer.Stop()
        Application.Documents.Open(FileName:=FileToOpen)
      Catch ex As Exception
        MsgBox("Error Opening '" & System.IO.Path.GetFileName(FileToOpen) & vbCrLf &
          ex.Message)
      End Try
    End Sub


    Tim

    • Marked as answer by Tim_Shaf Friday, February 24, 2012 7:24 PM
    Thursday, February 23, 2012 3:15 PM
  • Looks like you are correct: unloading FileB ulocks FileA. Note that you can delete the original file later, in Word.Quit() or even in the next session.


    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader

    Please mark answers and useful posts to help other developers use the forums efficiently.

    Friday, February 24, 2012 5:09 PM
  • Hello Andrei,

    I've tried this solution but, contrary to others, it's not working for me. The call to InvokeMember throws an exception with error DISP_E_UNKNOWNNAME. I've tried this with the exact code you posted with Word 2007 and 2010, and also tried it in Visual Basic language, fearing that InvokeMember call could have wrong parameters, but the result is still the same. It seems that WordBasic doesn't have a "IsAutosaveEvent" property indeed. Could you please provide any help with this?

    Thanks.

    Thursday, May 9, 2013 1:22 PM