不能将Excel工作簿标记为最终

情况如下:

我们想发布一个本地编辑的文件到远程机器。 这个文件可以是Word,Excel,Powerpointtypes。 显然,在发布到远程机器之后,我们希望本地文档被标记为最终的,以防止用户再次编辑(因为所需的工作stream程首先从远程服务器下载,编辑下载文档并将其发布回服务器)。

所以,有一堆这样的代码:

Public Sub setDocFinal() Select Case addin.HostType Case ADXOfficeHostApp.ohaWord Dim doc As Word.Document = Nothing Try doc = addin.WordApp.ActiveDocument doc.Final = True Catch ex As Exception Throw New Exception(Me.addin.getLabel("cannotSaveCopy", "Cannot Save the document.")) Finally Marshal.ReleaseComObject(doc) End Try Case ADXOfficeHostApp.ohaExcel Dim doc As Excel.Workbook = Nothing Try doc = addin.ExcelApp.ActiveWorkbook doc.Final = True 'doc.RefreshAll() 'doc.CalculateUntilAsyncQueriesDone() 'doc.Calculate() Catch ex As Exception Throw New Exception(Me.addin.getLabel("cannotSaveCopy", "Cannot Save the document.")) Finally Marshal.ReleaseComObject(doc) End Try ' Powerpoint case intentionally skipped as is has same format/code End Select End Sub 

上面的代码对于Word来说工作得非常好,但是对于Excel来说,它会堆栈在popup窗口中,通知用户将发布操作发送到远程服务器: 在这里输入图像说明

编辑
在那个特定点,执行冻结(或者进入一个无限的内部循环,因为在debugging模式下只有可用的button是暂停和停止)在设置文档为最终的行,它永远不会达到finally声明释放对象)。 它也似乎像执行试图将控制权返回到Excel文档,但没有什么比这个通知发生:

在这里输入图像说明

任何关于上述代码中的错误的想法,关于Excel的处理?
评论中的行显示了我正在经历的一些试验,同时试图find解决scheme。

另外,这里也是popup窗口的相关代码:

 Private Sub doWork(ByVal action As String, ByVal e As System.ComponentModel.DoWorkEventArgs) Dim myDoc As MyDocument myDoc = DirectCast(e.Argument, MyDocument) System.Diagnostics.Debug.WriteLine("Post in Thread") Dim resultObject(3) As Object resultObject(0) = True resultObject(1) = myDoc Dim saveDocumentResult As SaveDocumentResult = Nothing Try Select Case action Case Constants.SAVE_DRAFT saveDocumentResult = myDoc.getRequestService().saveDraft(myDoc.getSaveFile(), myDoc.getDocName(), myDoc) Case Constants.PUBLISH saveDocumentResult = myDoc.getRequestService().publishDocument(myDoc.getSaveFile(), myDoc.getDocName(), myDoc) myDoc.setDocFinal() 'this line makes the call to the above code End Select myDoc.updateDocumentProperty(Constants.VERSION, saveDocumentResult.version) myDoc.updateDocumentProperty(Constants.HASH, saveDocumentResult.hash) myDoc.setSaved(True) System.Threading.Thread.Sleep(1500) Catch ex As Exception resultObject(0) = False resultObject(2) = ex.Message Finally e.Result = resultObject End Try End Sub