Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Working with a .exe file

Hi all,

I have a software ending with .exe that i would like to open, type
the
word 'select' on it, press 'enter' and make it run.


I used the following code :


wb = Shell("Y:\Programs\Sel.exe", 1)
Application.Wait Now() + TimeValue("00:00:15")

SendKeys "select"
SendKeys "{ENTER}"

but the Sel.exe either copies the text "select" on my vbe editor
or shows the text "select" but it doesn't
recognize it.
When I open Sel.exe and I type "select" + "{ENTER}", without using vba
code,it works.

Any helps?


Thanks,
Marco

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Working with a .exe file

Marco,
If you must post to more than one NG, cross-post, not multi-post.
And stick to one thread.
You now have 4 threads in 2 NGs on the same subject, with replies but no
feedback from you.

NickHK

"Marco" wrote in message
oups.com...
Hi all,

I have a software ending with .exe that i would like to open, type
the
word 'select' on it, press 'enter' and make it run.


I used the following code :


wb = Shell("Y:\Programs\Sel.exe", 1)
Application.Wait Now() + TimeValue("00:00:15")

SendKeys "select"
SendKeys "{ENTER}"

but the Sel.exe either copies the text "select" on my vbe editor
or shows the text "select" but it doesn't
recognize it.
When I open Sel.exe and I type "select" + "{ENTER}", without using vba
code,it works.

Any helps?


Thanks,
Marco



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Working with a .exe file

I think the trouble might be that Shell doesn't wait till the .exe is fully
launched, so
your next code line doesn't target the .exe.
Try to launch your .exe with this code:


Option Explicit
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type

Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadId As Long
End Type

Private Declare Function WaitForSingleObject _
Lib "kernel32" (ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As
Long

Private Declare Function CreateProcessA _
Lib "kernel32" (ByVal lpApplicationName As String,
_
ByVal lpCommandLine As String, _
ByVal lpProcessAttributes As Long,
_
ByVal lpThreadAttributes As Long,
_
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, _
ByVal lpCurrentDirectory As
String, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As
PROCESS_INFORMATION) As Long

Private Declare Function GetExitCodeProcess _
Lib "kernel32" (ByVal hProcess As Long, _
lpExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Const NORMAL_PRIORITY_CLASS = 32


Sub test()

'experiment with the 1000 as you may need less or even 0
ExecCmd "C:\WINDOWS\SYSTEM32\notepad.exe", 1000, True

End Sub


Function ExecCmd(sCmdLine As String, _
lmSecsWait As Long, _
Optional bShowWindow As Boolean) As Long

'will start an external process and
'wait till this process is finished
'returns -1 if successfull and -1 if not
'-----------------------------------------
Dim proc As PROCESS_INFORMATION
Dim Start As STARTUPINFO
Dim lReturn As Long

'Initialize the STARTUPINFO structu
With Start
.cb = Len(Start)
.dwFlags = 1 'hexadecimal would be &H1
If bShowWindow Then
.wShowWindow = 1
End If
End With

'Start the shelled application:
lReturn = CreateProcessA(sCmdLine, _
vbNullString, _
0, _
0, _
1, _
NORMAL_PRIORITY_CLASS, _
0, _
vbNullString, _
Start, _
proc)

'Wait for the shelled application to finish:
lReturn = WaitForSingleObject(proc.hProcess, lmSecsWait)
GetExitCodeProcess proc.hProcess, lReturn
CloseHandle proc.hThread
CloseHandle proc.hProcess
ExecCmd = lReturn

End Function


RBS


"Marco" wrote in message
oups.com...
Hi all,

I have a software ending with .exe that i would like to open, type
the
word 'select' on it, press 'enter' and make it run.


I used the following code :


wb = Shell("Y:\Programs\Sel.exe", 1)
Application.Wait Now() + TimeValue("00:00:15")

SendKeys "select"
SendKeys "{ENTER}"

but the Sel.exe either copies the text "select" on my vbe editor
or shows the text "select" but it doesn't
recognize it.
When I open Sel.exe and I type "select" + "{ENTER}", without using vba
code,it works.

Any helps?


Thanks,
Marco


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Working with a .exe file

Thanks RBS but the problem still remains.
Your code is great in the sense that the text I want to type in
the .exe file is typed in correctly but when it executes by the
SendKeys "{ENTER}",
it gives an error message.
In the case I let the vba code open the file and then it is me to
enter "select + "{ENTER}", the .exe file still doesn't work.
In the case I open the file normally without vba code and i type in
"select + "{ENTER}" it works properly.

i'm really confused !!!??!!


Option Explicit
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type


Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadId As Long
End Type


Private Declare Function WaitForSingleObject _
Lib "kernel32" (ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long

Private Declare Function CreateProcessA _
Lib "kernel32" (ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, _
ByVal lpProcessAttributes As Long, _
ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, _
ByVal lpCurrentDirectory As String, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long


Private Declare Function GetExitCodeProcess _
Lib "kernel32" (ByVal hProcess As Long, _
lpExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Const NORMAL_PRIORITY_CLASS = 32


Sub test()


'experiment with the 1000 as you may need less or even 0
ExecCmd "Y:\Programs\Sel.exe", 100000, True

End Sub



Function ExecCmd(sCmdLine As String, _
lmSecsWait As Long, _
Optional bShowWindow As Boolean) As Long


'will start an external process and
'wait till this process is finished
'returns -1 if successfull and -1 if not
'-----------------------------------------
Dim proc As PROCESS_INFORMATION
Dim Start As STARTUPINFO
Dim lReturn As Long


'Initialize the STARTUPINFO structu
With Start
.cb = Len(Start)
.dwFlags = 1 'hexadecimal would be &H1
If bShowWindow Then
.wShowWindow = 1
End If
End With


'Start the shelled application:
lReturn = CreateProcessA(sCmdLine, _
vbNullString, _
0, _
0, _
1, _
NORMAL_PRIORITY_CLASS, _
0, _
vbNullString, _
Start, _
proc)


'Wait for the shelled application to finish:
lReturn = WaitForSingleObject(proc.hProcess, lmSecsWait)
SendKeys "Select"
' SendKeys "{ENTER}"
GetExitCodeProcess proc.hProcess, lReturn
CloseHandle proc.hThread
CloseHandle proc.hProcess
ExecCmd = lReturn


End Function





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Working with a .exe file

it gives an error message.

What error message?
Maybe you need some other keystrokes to set the focus
on the right button in that app and only then send ENTER.

RBS


"Marco" wrote in message
oups.com...
Thanks RBS but the problem still remains.
Your code is great in the sense that the text I want to type in
the .exe file is typed in correctly but when it executes by the
SendKeys "{ENTER}",
it gives an error message.
In the case I let the vba code open the file and then it is me to
enter "select + "{ENTER}", the .exe file still doesn't work.
In the case I open the file normally without vba code and i type in
"select + "{ENTER}" it works properly.

i'm really confused !!!??!!


Option Explicit
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type


Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadId As Long
End Type


Private Declare Function WaitForSingleObject _
Lib "kernel32" (ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long

Private Declare Function CreateProcessA _
Lib "kernel32" (ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, _
ByVal lpProcessAttributes As Long, _
ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, _
ByVal lpCurrentDirectory As String, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long


Private Declare Function GetExitCodeProcess _
Lib "kernel32" (ByVal hProcess As Long, _
lpExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Const NORMAL_PRIORITY_CLASS = 32


Sub test()


'experiment with the 1000 as you may need less or even 0
ExecCmd "Y:\Programs\Sel.exe", 100000, True

End Sub



Function ExecCmd(sCmdLine As String, _
lmSecsWait As Long, _
Optional bShowWindow As Boolean) As Long


'will start an external process and
'wait till this process is finished
'returns -1 if successfull and -1 if not
'-----------------------------------------
Dim proc As PROCESS_INFORMATION
Dim Start As STARTUPINFO
Dim lReturn As Long


'Initialize the STARTUPINFO structu
With Start
.cb = Len(Start)
.dwFlags = 1 'hexadecimal would be &H1
If bShowWindow Then
.wShowWindow = 1
End If
End With


'Start the shelled application:
lReturn = CreateProcessA(sCmdLine, _
vbNullString, _
0, _
0, _
1, _
NORMAL_PRIORITY_CLASS, _
0, _
vbNullString, _
Start, _
proc)


'Wait for the shelled application to finish:
lReturn = WaitForSingleObject(proc.hProcess, lmSecsWait)
SendKeys "Select"
' SendKeys "{ENTER}"
GetExitCodeProcess proc.hProcess, lReturn
CloseHandle proc.hThread
CloseHandle proc.hProcess
ExecCmd = lReturn


End Function








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Working with a .exe file

RBS,

the error is that it says that another file to which the .exe file is
linked to could not be found.

But when i type in the text "select" by keyboard it recognize it.

what i'm thinking is that maybe the font from excel vba is different
or that there is a sort of incompatibility between them.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Working with a .exe file

I don't think fonts come into it.

RBS

"Marco" wrote in message
ups.com...
RBS,

the error is that it says that another file to which the .exe file is
linked to could not be found.

But when i type in the text "select" by keyboard it recognize it.

what i'm thinking is that maybe the font from excel vba is different
or that there is a sort of incompatibility between them.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I auto save to a separate file?(not the file I am working in) Jim Lynch Setting up and Configuration of Excel 1 August 14th 06 05:20 PM
Prevent file from working Steph[_6_] Excel Programming 6 October 7th 05 04:06 PM
Code is working in one file but not in another. shilps Excel Programming 1 April 19th 04 12:20 PM
SaveAs another file name, then keep working L Mehl Excel Programming 2 February 24th 04 02:11 AM
show the working file Grey Excel Programming 1 January 10th 04 03:26 AM


All times are GMT +1. The time now is 04:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"