Quantcast
Channel: Word for Developers forum
Viewing all articles
Browse latest Browse all 4350

Determine if Word running using Dim processes As Process() = Process.GetProcessesByName("winword.exe")

$
0
0

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




Viewing all articles
Browse latest Browse all 4350

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>