Wigmans
asked on
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.
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.
It appears a problem with Office version not windows version. Word97 opens documents in the same window but Word2000 opens in a separate instance.
ASKER
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.Applica tion")
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
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.Applica
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
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.Applica tion")
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(sPa th)
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
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.Applica
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(sPa
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
ASKER
Same behaviour.
Etxra info. This behaviour only occure if you compile the application and run the executable
Etxra info. This behaviour only occure if you compile the application and run the executable
then..., i can't help you. Sorry.
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
Moderator, my recommended disposition is:
Refund points and save as a 0-pt PAQ.
DanRollins -- EE database cleanup volunteer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.