【发布时间】:2019-07-12 20:30:45
【问题描述】:
我正在开发一个实用程序来查找和更新 Word 中的 DOC 变量。我有一段代码可以遍历文档并显示带有变量名称的消息框,但是当它尝试打开下一个文档时收到错误消息。错误是:
System.Runtime.InteropServices.COMException: 'RPC 服务器不可用。 (HRESULT 异常:0x800706BA)
我很困惑,因为我的代码没有访问任何网络。我认为可能发生的情况是文档关闭时 Word 正在关闭,但我找不到防止这种情况发生的解决方案。
我尝试过的其他事情:
- 已确认 UAC 已禁用
- 已确认 RPC 服务正在运行
-
已确认 RPC 和 DCOM 的注册表值正确
Private Sub LoopTemp() Dim oDir As New DirectoryInfo(dPath) Dim oFileArr As FileInfo() = oDir.GetFiles() Dim oFile As FileInfo Dim oVar As Variable Dim oDoc = New Document() Dim oWord As Application oWord = CreateObject("Word.Application") oWord.Visible = False For Each oFile In oFileArr oDoc = oWord.Documents.Open(oFile.FullName) For Each oVar In oDoc.Variables MsgBox(oVar.Name) Next oDoc.Close(SaveChanges:=WdSaveOptions.wdSaveChanges) Next oWord.Quit() End Sub
【问题讨论】:
-
你在哪里运行上面列出的代码?是来自asp.net还是service?
标签: vb.net ms-word office-interop