Check if Word is running!

Hello,

I tried to start Word from a VB.2005 Application. When Word ist still running i will use this Word instance. How do i get the running Word instance

Imports System
Imports System.Reflection ' For Missing.Value and BindingFlags
Imports System.Runtime.InteropServices ' For COMException
Imports Microsoft.Office.Interop.Word
Public Class Print
Private app As Microsoft.Office.Interop.Word.Application
Private Sub New()

app = New Application()

If app Is Nothing Then
Exit Sub
End If

End Sub
End Class

We want to programm an Programm that uses only .NET 2 Framework Komponents.
So that:


app = GetObject(, "Word.Application")

is not available. What other ways do I have to get the running Word instance

Thanks.

Daniel




Answer this question

Check if Word is running!

  • tun

    IF you dont want to put an imports in you project then just fully qualify the method.

    Dim obj As Object

    obj = Microsoft.VisualBasic.GetObject(, "Word.Application")

    All the imports statement is doing is just meaning that you dont have to fully qualify all the methods in the Microsoft.VisualBasic namespace. It saves you typing. You could put this imports statement at the project level or file level or not at all if you want to fully qualify the method

    But if your writing a visual basic application you would need to have fully qualify the methods to the correct namespace methods are used. Thats why this default imports is set for a visual basic project - so that you dont need to fully qualify the methods for Visual Basic.

    This microsoft.visualbasic namespace is shipped with the framework - which is required to run vb.net applications. So whats the issue with not microsoft.visualbasic - as I assume you are writing a visual basic application to get a running instance of word. In which case you are running a visual basic application.



  • Art Vandolay Jr.

    When you use the

    Dim obj As Object

    obj = GetObject(, "Word.Application")


    Statement, you must import Microsoft.VisualBasic. Because the GetObject() function ist in Microsoft.VisualBasic. This is what i don`t want. Is there a other way to get the running Word instance without implementing Microsoft.VisualBasic

  • Michael Cochran

    Why not

  • danoliv

    I'm not sure if I understand what you're trying to do - I started word, and ran a simple program:

    Module Module1

    Sub Main()

    Dim obj As Object

    obj = GetObject(, "Word.Application")

    obj.activedocument.content.text = "testing"

    Console.WriteLine(obj.activedocument.content.text)

    End Sub

    End Module

    This seems to work - it changed the currently open word document.

    Are you looking for a way to start word without using office's libraries



  • Check if Word is running!