Call other application from excel

  • Thread starter Thread starter A-Design
  • Start date Start date
A

A-Design

Hi,

I am using Shell ("c:\Program Files\X\X.EXE") to run another program from
excel , now how can I make this code to open a specific file for me actually
in this case both excel and X application are using the same file name but
the extensions are like 04094.xls and 04094.XXX .

Thanks in advance.
Afshin
 
If I understand correctly you are asking about this:

fileOpen = Shell("c:\Program Files\X\X.EXE " & "c:\myfolder\04094.XXX",
vbMaximizedFocus)

KL
 
That is it,
Thank you KL,


KL said:
If I understand correctly you are asking about this:

fileOpen = Shell("c:\Program Files\X\X.EXE " & "c:\myfolder\04094.XXX",
vbMaximizedFocus)

KL
 
Can either of you tell me how I would use shell to accomplish this task
I have macro's that have been created via VB in EXCEL - I have been
 
Kathy

you could try the shellwait function
(not fully tested)
RetVal = Shell("command.com /c nbtstat -a " & sMachineID , 0)
based on the snippet of code that does/did work:
RetVal = Shell("command.com /c nbtstat -a " & sMachineID & " > " &
Environ$("temp") & "\" & sMachineID & ".txt", 0)

hth

Tim

the shellwait code is reproduced below incl a dummy test (put code in its
own module for convenience):

Option Explicit

Private Const PROCESS_QUERY_INFORMATION As Long = &H400
Private Const STILL_ACTIVE As Long = &H103

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess
As _
Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long

Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess
As _
Long, lpExitCode As Long) As Long


Sub TestShellAndWait()
Dim Ret_Val_

ShellAndWait ("command.com /c dir s: > c:\temp\junk.txt")
'ShellAndWait ("command.com dir c:\*.* > c:\temp\junk.txt")

End Sub

''' Arguments: szCommandLine The command line to execute using Shell.
''' iWindowState (Optional) The window state parameter to
pass
''' to the Shell function. Default = vbHide.
''' See Shell function help for other options.
Sub ShellAndWait(ByVal szCommandLine As String, Optional ByVal iWindowState
As _
Integer = vbHide)

Dim lTaskID As Long
Dim lProcess As Long
Dim lExitCode As Long
Dim lResult As Long

''' Run the Shell function.
lTaskID = Shell(szCommandLine, iWindowState)

''' Get the process handle from the task ID returned by Shell.
lProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0&, lTaskID)

''' Loop while the shelled process is still running.
Do
''' lExitCode will be set to STILL_ACTIVE as long as the shelled
process is running.
lResult = GetExitCodeProcess(lProcess, lExitCode)
DoEvents
Loop While lExitCode = STILL_ACTIVE

End Sub
 
KL,
Have you tried this on your system ? Is it working for you ? please see my
2nd post that I have sent yesterday.
Thanks,
Afshin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top