Click to See Complete Forum and Search --> : What value do I have to put in AppActivate


regis
February 17th, 2000, 08:37 AM
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

rpouliot@iqaff.qc.ca

Ravi Kiran
February 18th, 2000, 03:20 AM
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