Solved

Get window handle from second Word-document

Posted on 2002-06-20
7
486 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:Wigmans
Comment Utility
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
Comment Utility
then..., i can't help you. Sorry.
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
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
Comment Utility
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now