I am automating a word document which is getting generated each time i click a button in a web page, i am able to get hold of that WINWORD.EXE process but unable to set it to a word type variable. This is what i had tried:
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
Dim reVal as Object = Marshal.GetActiveObject(ProgID) throws error:
System.Runtime.InteropServices.COMException: 'Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))'
User contributions licensed under CC BY-SA 3.0