Results 1 to 2 of 2

Thread: Setting focus to another open app?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2001
    Posts
    20

    Question Setting focus to another open app?

    From my vb app how would I get a handle to an **open** word document and set focus to it??

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Try this. Note: This will work if the document is open, but NOT minimized, but rather, running in the background. Also, you must know what the caption of the document is.
    VB Code:
    1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    2. Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
    3.  
    4. Private Sub Command1_Click()
    5. Dim WinWnd As Long
    6. Dim ShowWin As Long
    7.     WinWnd = FindWindow(vbNullString, "Employee Appraisal Form.doc - Microsoft Word")
    8.     If WinWnd = 0 Then
    9.        MsgBox "Document not found"
    10.     Else
    11.        ShowWin = SetForegroundWindow(WinWnd)
    12.     End If
    13. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width