testing if a word document is open within Access (several instances of word)

  • Thread starter Jean-Paul HORN via AccessMonster.com
  • Start date
J

Jean-Paul HORN via AccessMonster.com

I want to test if a word document is open within Access. The point is that
I can have several instances of word opened in the same time.

the getObject function works only if the document is open in the first
instance of Word.

I'have tried with WMI scripting. If managed to list all the instances of
word, but I couldn't test if any document was opened.

So my question is : how can I test if a Word Document is open when it is
not in the first instance of word, and how can I activate it ? (if possible
without terminating the other instances of Word)

thanks for help

jean-Paul
 
J

John Nurick

Does the person in charge realise that their decision will cost maybe
four times as much of your time as doing it the sane way?

If so, treat it as an enjoyable opportunity to learn the Windows API at
someone else's expense<g>.

I've just had a thought: It may be simpler to tackle this crazy task by
using VB rather than VBA, and packaging the function(s) in a custom DLL.
 
N

Norman Goetz

Hello Jean-Paul

Some older Code below

I agree with you, and I suggested the same solution as the one you have
proposed in your last email, but the person in charge of the programming
has decided not to change the code.

So I have to find another solution.

JP

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Public Sub demoWord()
Dim objWord As Word.Application
Set objWord = detDoc("<INSERT_DOCUMENTNAME_HERE>")
If TypeName(objWord) <> "Nothing" Then
'Found an Instance of Word and the Document
objWord.Quit SaveChanges:=False
End If
Set objWord = Nothing
End Sub

Public Function detDoc(ByVal strDocument As String) As
Word.Application
Dim lngChan As Long
Dim strTopic As String
Dim objDoc As Word.Document
Dim objWord As Word.Application
Dim varArr
Dim lngCount As Long
Dim lngHwnd As Long
lngHwnd = FindWindow("OpusApp", vbNullString)
If lngHwnd Then
lngChan = DDEInitiate("Winword", "System")
strTopic = DDERequest(lngChan, "Topics")
DDETerminate lngChan
varArr = Split(strTopic, Chr$(9))
For lngCount = 0 To UBound(varArr)
If LCase$(varArr(lngCount)) = LCase$(strDocument) Then
Set objDoc = GetObject(strDocument)
Set objWord = objDoc.Application
Set detDoc = objWord
Exit Function
End If
Next lngCount
End If
Set detDoc = Nothing
End Function


Norman Goetz
 
J

Jean-Paul HORN via AccessMonster.com

thank you to all of you.
With all your advices I think I'll be able to find out a suitable solution

Jean-Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top