How to send a command line to Windows torun an external application

mtheriault2000

Well-known Member
Joined
Oct 23, 2008
Messages
826
Hello

I have done it in the past, but just can't remember how.

I need to send a command line like
"C:\Program Files (x86)\HyperSnap 7\HprSnap7.exe" -snap:x3602:y155:w1432:h830 -save:jpg "g:\testsnap\asnap1.jpg"

This open my Snap picture application, take a snap at a give location and save the image to a jpg format at a given location

This command line work whell usingWindows. Now, I want tot send it from Excel vba

Martin
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
I use this in my projects and it works well
Code:
Public Sub ShellAndWait(ByVal PathName As String, Optional WindowState)
    Dim hProg As Long, hProcess As Long, ExitCode As Long

    If IsMissing(WindowState) Then WindowState = 1
    hProg = Shell(PathName, WindowState)

    hProcess = OpenProcess(&H400, False, hProg)
    Do
        GetExitCodeProcess hProcess, ExitCode
        DoEvents
    Loop While ExitCode = &H103
End Sub

then :

Code:
    ShellandWait ("C:\Program Files (x86)\HyperSnap 7\HprSnap7.exe" -snap:x3602:y155:w1432:h830 -save:jpg "g:\testsnap\asnap1.jpg")
 
Upvote 0
What could be wrong with the 2' shell command
Both file are under the same directory
Code:
Dim retval As Long

retval = Shell("C:\Program Files (x86)\HyperSnap 7\HprSnap7.exe" & " -hidden -newwin -snap:x3602:y155:w1432:h830 -save:jpg " & "g:\testsnap\asnap1.jpg -exit")
retval = Shell("C:\Program Files (x86)\HyperSnap 7\cameraclick1.wav")

Excel give me an error

If I copy the string to Windows Execute box, the .wav file is played

Martin
 
Last edited:
Upvote 0
i think you have to shell to an exe. windows is probably using the default exe lookup to determine which exe is being loaded before the .wav is opened. try using the sndPlaySound32 API call to play the .wav directly without shelling
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,936
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top