Solved

Get window handle from second Word-document

Posted on 2002-06-20
7
493 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

786 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