在Microsoft.Office.Interop.Word.DocumentClass.Save上获取0x800a1066命令失败错误

时间:2018-11-22 14:26:26

标签: vb.net ms-word vsto office-interop add-in

我正在使用具有以下代码的Word VSTO AddIn

Private Sub WordApp_DocumentBeforeClose(doc As Microsoft.Office.Interop.Word.Document, <Runtime.InteropServices.OutAttribute> ByRef Cancel As Boolean) Handles mWordApp.DocumentBeforeClose

    Try

        If Not Globals.ThisAddIn.EnableWordAddIn Then Return

        If mManagedDocuments.ContainsKey(doc.DocID) Then

            Dim closingDocument As PRADocument = mManagedDocuments(doc.DocID)

            If closingDocument IsNot Nothing Then

                ' Make sure we don't display this message for a none PRA document
                If closingDocument.IsPRADocument AndAlso Not closingDocument.WordDocument.ReadOnly Then
                    If Not closingDocument.WordDocument.Saved Then
                        ' 120020: "Do you want to save file ‘{0}’?"
                        If AddInMessageBox.Show(120020, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, closingDocument.WordDocument.Name) = DialogResult.Yes Then
                            closingDocument.WordDocument.Save()
                        Else
                            closingDocument.WordDocument.Saved = True
                        End If
                    End If

                    If closingDocument.ExpandedState = ExpandContractState.Expanded Then
                        ' If document is expanded when closing then contract it
                        DocumentExpandContract.ContractDocument(Globals.ThisAddIn.Application, closingDocument)
                        ' The expanded document will have been opened, but since we were closing we should close Word
                        mWordApp.Quit(False)
                        Return
                    End If

                ElseIf closingDocument.IsPRADocument AndAlso closingDocument.WordDocument.ReadOnly Then
                    ' If read-only don't prompt to save
                    closingDocument.WordDocument.Saved = True
                End If

            End If

            HandleDocumentClose(doc)

        End If

    Catch ex As Exception
        Util.DisplayException(ex)
    End Try

End Sub

关闭文档后,在Microsoft.Office.Interop.Word.DocumentClass.Save上获取0x800a1066命令失败的错误。

请帮助我分析什么会导致此错误?

此错误是间歇性的,并非每次都能重现。

0 个答案:

没有答案