Get window handle from second Word-document

Please can you give me an example how to get a Window Handle from the second MS Word-window.

I opened 2 Wordfiles in VB
In Window98 the last opened Word-document stay on top. In Windows 2000 this behaviour changed.
I want resolved this problem with SetForegroundWindow.
The first handle you can find with FindWindow(vbNull, WordApp.Caption) but the second one is my question.

Order is there an other solution for this problem.
WigmansAsked:
Who is Participating?
 
SpideyModConnect With a Mentor Commented:
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0
 
Richie_SimonettiIT OperationsCommented:
It appears a problem with Office version not windows version. Word97 opens documents in the same window but Word2000 opens in a separate instance.
0
 
WigmansAuthor Commented:
Hi Richie,

I tried this example once more in Windows 98 en 2000 with Office 2000.
As i already said i have still an problem in Windows 2000.
What do i wrong?

Private Sub cmdCallWord_Click()
   Dim sFile As String
   sFile="c:\test.doc"

   ' Start MS Word  and open file  
   CallWord sFile
   
End Sub


Sub CallWord(sPath As String)
   
   On Error Resume Next
   Set AppWord = GetObject(, "Word.Application")
   If Err.Number <> 0 Then
      Err.Clear
      On Error GoTo error
      Set AppWord = CreateObject("Word.Application")
      AppWord.Visible = True
   Else
      AppWord.Activate
   End If
   On Error GoTo error
   AppWord.WindowState = wdWindowStateMaximize
   AppWord.Activate
   
   AppWord.Documents.Open (sPath)
   
   Screen.MousePointer = vbDefault
   Set AppWord = Nothing

Exit Sub
error:
   Screen.MousePointer = vbDefault
   Set AppWord = Nothing
   MsgBox "Error CallWord:" & vbCr & Err.Number & vbCr & Err.Description
End Sub
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
Richie_SimonettiIT OperationsCommented:
Hope it helps:

Sub CallWord(sPath As String)
 
  On Error Resume Next
  Set AppWord = GetObject(, "Word.Application")
  If Err.Number <> 0 Then
     Err.Clear
     On Error GoTo error
     Set AppWord = CreateObject("Word.Application")
     AppWord.Visible = True
  Else
     AppWord.Activate
  End If
  On Error GoTo error
  AppWord.WindowState = wdWindowStateMaximize
  AppWord.Activate
  ' see here
  Dim wd As Object
  Set wd = AppWord.Documents.Open(sPath)
  wd.Activate
  ' see here
  Screen.MousePointer = vbDefault
  Set AppWord = Nothing

Exit Sub
error:
  Screen.MousePointer = vbDefault
  Set AppWord = Nothing
  MsgBox "Error CallWord:" & vbCr & Err.Number & vbCr & Err.Description
End Sub
0
 
WigmansAuthor Commented:
Same behaviour.

Etxra info. This behaviour only occure if you compile the application and run the executable
0
 
Richie_SimonettiIT OperationsCommented:
then..., i can't help you. Sorry.
0
 
DanRollinsCommented:
Wigmans, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:

    Refund points and save as a 0-pt PAQ.

DanRollins -- EE database cleanup volunteer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.