views:

31

answers:

1

Contrary to earlier versions (see here), I find that Word2007 places one entry into the Running Object Table for each instance of WinWord.exe that is running. (Using IROTVIEW.exe supplied with MS VC 6.0!)
I am trying to build an application that automates Word, and I would like to keep a hidden instance of Word unavailable to the user, while co-existing with a separate visible instance. Is there any way of preventing Word from registering itself in the ROT, or alternatively of ensuring that when the user double-clicks on a Word document, it is the visible instance that opens the document?

On reflection perhaps I should be asking a different question: when broadcasting a DDE message and there are multiple windows with the correct Application name, what determines which window gets to process the message first? I ask because I realise that the File Association for doc, docx extensions etc indicates that DDE will be used to open the document.

+1  A: 

Maybe I don't understand the question but a non visible instance is hidden for all practical purposes. The user won't be able to open that instance or any documents associated with it.

Public Sub Test()
    Dim currentDocument As Document

    Dim i As Long
    For i = 1 To 3
        Dim newApplication As Word.Application
        Set newApplication = CreateObject("Word.Application")
        Set currentDocument = newApplication.Documents.Add
        currentDocument.Range.InsertAfter "New instance " & i

        If i = 2 Then
            currentDocument.Windows(1).Visible = False
        Else
            currentDocument.Windows(1).Visible = True
        End If
    Next
End Sub
ForEachLoop