我正在自动执行一个Word文档,该文档在每次单击网页中的一个按钮时都会生成,我可以控制WINWORD.EXE进程,但无法将其设置为word类型变量。 这是我尝试过的:
Dim ProgID As String = "Word.Application"
Dim app as Word.Application
Dim doc as Word.Document
Dim p() As Process = Process.GetProcessesByName("WINWORD")
For Each itm As Process In p
If InStr(itm.MainWindowTitle, LetterType) > 0 Or
itm.MainWindowTitle = "" Then
Dim retVal As Object = Marshal.GetActiveObject(ProgID)
Try
app = Marshal.GetActiveObject(ProgID)
doc = app.ActiveDocument
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
Next
将reVal设为对象= Marshal.GetActiveObject(ProgID)会引发错误:
System.Runtime.InteropServices.COMException:'操作不可用(HRESULT的异常:0x800401E3(MK_E_UNAVAILABLE))'