Solved

Get window handle from second Word-document

Posted on 2002-06-20
7
498 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

827 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