|
-
Oct 6th, 2009, 06:26 AM
#1
Thread Starter
New Member
Sendkeys.sendwait doenst work. Why? and how to close an app opened thru shellexecute
Hi Gurus,
I am trying to automate an application (yeas, i am a novice!). Baiscally i need to run a software called traned from excel. The software doesnt have a com interface.
this thread is a follow up of my previous thread;
http://www.vbforums.com/showthread.p...09#post3624109
I have just 3 simple questions for you experts;
1) I am trying to use sendkeys.wait. but When i run the macros it comes up with 'compile error: Argument not optional'. If i use sendkeys only it works but its too fast! i need sendkeys to send keystrokes only when previous key strokes have finished!
2) How to terminate an application opened through shellexecute??
3) A better way to wait for the run to finish. I am using application.wait at the moment. but a better option is need due to variability in duration of runs.
I have search many forums but can't seem to find the right answer.
Please help!!
here is my code (for running the application once);
please note im using windows XP and office 07. Thanks
HTML Code:
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, _
ByVal nCmdShow As Long) As Long
Private Const SW_MAXIMIZE = 3
Private Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As Long) As Long
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 Sub Open_TranedFile()
'ShellExecute Application.hwnd, "open", "C:\Documents and Settings\naziz.EGR\Desktop\a.tnd", vbNullString, vbNullString, 1
'Application.Wait Now + TimeValue("00:00:06")
Dim hwndMs As Long
hwndMs = FindWindow("Afx:400000:8:10011:0:2ab0c27", vbNullString)
If hwndMs <= 0 Then MsgBox hwndMs
'MsgBox hwndMs
'Wait for application to load
'SetForegroundWindow (hwndMs)
Call ShowWindow(hwndMs, SW_MAXIMIZE)
SendKeys.SendWait "%"
SendKeys.SendWait "{right}"
SendKeys.SendWait "{right}"
SendKeys.SendWait "{right}"
SendKeys.SendWait "{right}"
SendKeys.SendWait "{right}"
SendKeys.SendWait "{right}"
SendKeys.SendWait "{right}"
SendKeys.SendWait "{right}"
SendKeys.SendWait "{right}"
SendKeys.SendWait "{down}"
SendKeys.SendWait "~"
End Sub
-
Oct 6th, 2009, 12:45 PM
#2
Re: Sendkeys.sendwait doenst work. Why? and how to close an app opened thru shellexec
Use the Sleep Api to introducing wait
vb Code:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Sub Sample() '~~> Rest of your code SendKeys "{right}" '~~> Sleep for 5 Seconds Sleep 5000 SendKeys "{right}" '~~> Rest of your code End Sub
For terminating...
vb Code:
Public Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, _ ByVal uExitCode As Long) As Long Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, _ ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long '~~> Example Usage: Retval = ShellExecute(Application.Hwnd, "Open", Sfile, vbNullString, _ vbNullString, vbMinimized) hProcess = OpenProcess(PROCESS_ALL_ACCESS, True, Retval) TermSucc = TerminateProcess(hProcess, 0)
Last edited by Siddharth Rout; Oct 6th, 2009 at 01:17 PM.
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 6th, 2009, 03:46 PM
#3
Thread Starter
New Member
Re: Sendkeys.sendwait doenst work. Why? and how to close an app opened thru shellexec
thank you so much for your response. I'll give it a go.
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|