CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 1999
    Location
    Québec (Canada)
    Posts
    210

    What value do I have to put in AppActivate

    I open Excel file with this code

    On Error Resume Next
    Dim lRet As Long
    Dim lOldCursor As Long
    lOldCursor = Screen.MousePointer
    Screen.MousePointer = vbHourglass
    lRet = ShellExecute(0, "open", sLinkTo, "", vbNull, SW_SHOWNORMAL)
    'MyAppID = Shell(sLinkTo, 1)
    'AppActivate MyAppID
    'SendKeys "^+G"
    If lRet >= 0 And lRet <= 0 Then
    Screen.MousePointer = vbDefault
    MsgBox "Erreur d'ouverture avec le fichier " & sLinkTo & vbCrLf & _
    vbCrLf & Err.LastDllError, , "ExecuteLink"
    End If
    Screen.MousePointer = vbDefault

    But am not able to use SendKeys. Am able to start my Excel file but am not able to start my macro Excel with "^+G"

    In the exemple code at line "lRet = Shell..." I start Excel File. The path file is in var "sLinkTo"

    When the Excel file is Started I will like to start macro Excel "^+G"

    I'am not familiar with function. Is't possible to you to help me.

    Sorry for my english

    Thanks
    Redg

    [email protected]


  2. #2
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: What value do I have to put in AppActivate

    Hi,
    Try this. Not a complete solution, but works for most part.
    Its doesn't work well for the case of Application (Word in this case) being active, but file not open. So check it and change as required.

    What you need is to wait for the application to become active enough to recieve your send keys. VBs Shell or ShellExecute return immediately, while the application is still starting up. So any info sent to it would be neglected. Specially for GUI processes, there is this function WaitForInputIdle

    ---

    option Explicit

    private Declare Function ShellExecute Lib "shell32.dll" _
    Alias "ShellExecuteA" (byval hwnd as Long, byval _
    lpOperation as string, byval lpFile as string, byval _
    lpParameters as string, byval lpDirectory as string, _
    byval nShowCmd as Long) as Long
    private Declare Function WaitForInputIdle Lib "user32" (byval hProcess as Long, byval dwMilliseconds as Long) as Long

    private Declare Function ShellExecuteEx Lib "shell32.dll" _
    Alias "ShellExecuteExA" (lpShellExecuteInfo as Any) as Long
    ' as Any pointer above is actually of type ShellExecuteInfo Structure
    private Type SHELLEXECUTEINFO
    cbSize as Long
    fMask as Long
    hwnd as Long
    lpVerb as string
    lpFile as string
    lpParameters as string
    lpDirectory as string
    nShow as Long
    hInstApp as Long
    ' optional fields
    lpIDList as Long
    lpClass as string
    hkeyClass as Long
    dwHotKey as Long
    hIcon as Long
    hProcess as Long
    End Type
    ' fmask Values:
    Const SEE_MASK_NOCLOSEPROCESS = &H40&

    Const SW_SHOWNORMAL = 1

    private Sub Command1_Click()
    Dim szfilename as string
    Dim lrtn as Long

    szfilename = "d:\trk\trk-temp\Comprev.doc"
    Dim tmpSHEinfo as SHELLEXECUTEINFO
    tmpSHEinfo.cbSize = len(tmpSHEinfo)
    tmpSHEinfo.fMask = SEE_MASK_NOCLOSEPROCESS
    tmpSHEinfo.hwnd = 0
    tmpSHEinfo.lpVerb = "Open"
    tmpSHEinfo.lpFile = szfilename
    tmpSHEinfo.nShow = SW_SHOWNORMAL

    'Call ShellExecute(me.hwnd, "open", szfilename, 0, 0, SW_SHOWNORMAL)
    lrtn = ShellExecuteEx(tmpSHEinfo)
    If lrtn = 0 then
    MsgBox "ShellExecuteEx failed!!. GLE=" & Str(Err.LastDllError)
    else
    Debug.print tmpSHEinfo.hProcess
    'MsgBox "Wait starting..."
    WaitForInputIdle tmpSHEinfo.hProcess, 12
    'MsgBox "Finished waiting>>>"
    ' *** IF the above message boxes are uncommented, then (focus would have
    ' *** moved back to the VB program, so we need to set it back using
    ' *** appActivate. So uncomment the below line also:
    'AppActivate tmpSHEinfo.hInstApp
    SendKeys "{Enter} + {Enter} + {Enter}"
    'SendKeys "^f" ' - brings up search list
    '*** However if the file is closed, and WORD app is on,
    ' *** then the above line is resulting in some error in WORD.!
    ' *** "Word Basic error 509" !?!
    End If
    End Sub





    RK

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

Featured