I have a Winforms application that launches Word to automate and edit documents.
I would like to check if Word (WINWORD.EX) is already running.
if Word is running then
use the existing session of Word
Else
Create a new instance of Word
End if
The code is in my main module.
I use the following code
It errors on the dim on
Process.GetProcessesByName("winword.exe")
With Argument not specified for parameter 'Params' of 'Private Sub Process(Params As Object)'.
Do I need to import a library
What am I doing wrong?
Dim objWordApp As Word.Application Dim processes As Process() = Process.GetProcessesByName("winword.exe") If processes.Length = 0 Then MsgBox("Winword.exe is running") objWordApp = CType(Marshal.GetActiveObject("Word.Application"), Word.Application) Else MsgBox("Winword.exe NOT running") objWordApp = New Microsoft.Office.Interop.Word.Application End If
https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.getprocessesbyname?view=netframework-4.8
TIA