Results 1 to 4 of 4

Thread: AppActivate

  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Utah, USA
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    AppActivate

    Is this the correct way to us AppActivate: AppActivate "1 - Default (ibm)", True? I'm trying to send key strokes to the ibm window and keep getting the following error message: Invalid procedure call or argument.

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: AppActivate

    Is that the string that appears in the title bar of the window you're trying to call? If not, it won't work regardless. Since I don't know what you mean by the ibm window, I can only suggest you look at the following examples from VBA help:

    <pre>Dim MyAppID, ReturnValue</pre>


    <pre>AppActivate "Microsoft Word" ' Activate Microsoft _
    ' Word.</pre>


    <pre>' AppActivate can also use the return value
    ' of the Shell function.
    ' Run Microsoft Word.
    MyAppID = Shell("C:WORDWINWORD.EXE", 1)
    AppActivate MyAppID ' Activate Microsoft
    ' Word.</pre>



    <pre>' You can also use the return value of
    ' the Shell function.
    ' Run Microsoft Excel.
    ReturnValue = Shell("c:EXCELEXCEL.EXE",1)
    AppActivate ReturnValue ' Activate Microsoft
    ' Excel.</pre>

    Charlotte

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Utah, USA
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: AppActivate

    Charlotte,

    I tried the examples you gave and still get the same error message. I am trying to sendkeys to an IBM mainframe window from my Access database. Access will not allow focus to be transfered to the mainframe window.

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: AppActivate

    VBA and Office do not appear to offer any user-friendly methods for what you need to do: snag the exact identifier of the IBM window. Here is some code to help find it, and then (hopefully) you can AppActivate it. Note that you won't need both of these functions, just use the one you prefer.

    <pre>Option Explicit
    'first function interates through running processes
    Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, _
    ByVal wCmd As Long) As Long
    'next function is a place to start
    Declare Function GetDesktopWindow Lib "user32" () As Long
    'check whether this is the top window of the app
    Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
    'next function gets title bar if any
    Declare Function GetWindowText Lib "user32" Alias _
    "GetWindowTextA" (ByVal hwnd As Long, _
    ByVal lpString As String, ByVal cch As Long) As Long

    Sub JustTesting()
    Dim strAppUniqueSubString As String
    strAppUniqueSubString = "microsoft outlook"
    MsgBox "Handle of " & strAppUniqueSubString & " is: " & _
    lngWinHandle(strAppUniqueSubString)
    MsgBox "Window title containing " & strAppUniqueSubString & _
    " is: " & strWinTitle(strAppUniqueSubString)
    End Sub

    Function lngWinHandle(strTitleText As String) As Long
    'Finds first window that contains the supplied text string
    'Copyright 2001 Jefferson F. Scher
    'Set constants for GetWindow
    Const GW_HWNDFIRST = 0
    Const GW_HWNDLAST = 1
    Const GW_HWNDNEXT = 2
    Const GW_HWNDPREV = 3
    Const GW_OWNER = 4
    Const GW_CHILD = 5
    Const GW_MAX = 5
    'Define local variables
    Dim lnghWnd As Long, intLenTitle As Integer, strTitle As String
    'Retrieve "handle" for a window known to exist
    lnghWnd = GetWindow(GetDesktopWindow(), GW_CHILD)
    'Iterate through all other windows seeking the supplied text string
    Do While lnghWnd <> 0
    If GetParent(lnghWnd) = 0 Then 'this is not a child window
    strTitle = String(255, " ")
    intLenTitle = GetWindowText(lnghWnd, strTitle, 255)
    If intLenTitle <> 0 Then
    If InStr(1, strTitle, strTitleText, vbTextCompare) <> 0 Then
    lngWinHandle = lnghWnd
    Exit Function
    End If
    End If
    End If
    lnghWnd = GetWindow(lnghWnd, GW_HWNDNEXT)
    Loop
    'if we get here, we have no match
    lngWinHandle = 0
    End Function

    Function strWinTitle(strTitleText As String) As String
    'Finds first window that contains the supplied text string
    'Copyright 2001 Jefferson F. Scher
    'Set constants for GetWindow
    Const GW_HWNDFIRST = 0
    Const GW_HWNDLAST = 1
    Const GW_HWNDNEXT = 2
    Const GW_HWNDPREV = 3
    Const GW_OWNER = 4
    Const GW_CHILD = 5
    Const GW_MAX = 5
    'Define local variables
    Dim lnghWnd As Long, intLenTitle As Integer, strTitle As String
    'Retrieve "handle" for a window known to exist
    lnghWnd = GetWindow(GetDesktopWindow(), GW_CHILD)
    'Iterate through all other windows seeking the supplied text string
    Do While lnghWnd <> 0
    If GetParent(lnghWnd) = 0 Then 'this is not a child window
    strTitle = String(255, " ")
    intLenTitle = GetWindowText(lnghWnd, strTitle, 255)
    If intLenTitle <> 0 Then
    If InStr(1, strTitle, strTitleText, vbTextCompare) <> 0 Then
    strWinTitle = strTitle
    Exit Function
    End If
    End If
    End If
    lnghWnd = GetWindow(lnghWnd, GW_HWNDNEXT)
    Loop
    'if we get here, we have no match
    strWinTitle = vbNullString
    End Function
    </pre>

    One other thought: if Access wants to stay on top, you might want to try minimizing it.

Posting Permissions

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