?
Solved

Get window handle from second Word-document

Posted on 2002-06-20
7
Medium Priority
?
507 Views
Last Modified: 2008-02-01
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.
0
Comment
Question by:Wigmans
7 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7099095
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
 

Author Comment

by:Wigmans
ID: 7105785
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7108579
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Wigmans
ID: 7113370
Same behaviour.

Etxra info. This behaviour only occure if you compile the application and run the executable
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7113579
then..., i can't help you. Sorry.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7923714
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
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 7968436
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question