has anybody come across this before?

J

Jason

this is just an example i am using to point out, i am trying to open command
prompt, and run something in it from vba.

Private Sub cmd1_Click()
Dim OldPath As String
Dim NewPath As String
a = 13048
b = " VQRUN" & " " & a & ".prn" & " " & a & ".out"
'vqrun is the name of the program that i wanted to run in command prompt
'and 13048.prn and 13048.out are the parameters passed to the application
vqrun.

OldPath = CurDir
NewPath = "C:\VQ80_2\ "
ChDrive NewPath
ChDir NewPath


', now, it opens the cmd prompt with the new path, which is fine(c:\vq80_2),
but now i need to run 'vqrun along wit the parameters'.

i know that the below line is wrong because i cannot simply add 'b', but is
there anyway i could do this?
ret = Shell("c:\winnt\system32\cmd.exe", b)


anyhelp on this is much much appreciated because i have been waiting for the
answer of this question for a long time. cheers.
 
B

Bernie Deitrick

Jason,

Shell will actually run the program directly:

ret = Shell(b)

but note that b is a string, and it is possible that VQRUN requires double quote delimited string
parameters as inputs, in which case you would need to insert " characters - done by inserting ""
into your line like so:

b = " VQRUN" & " """ & a & ".prn""" & " """ & a & ".out"""

HTH,
Bernie
MS Excel MVP
 
J

Jason

Hello Bernie, sorry that i posted this in two places because i was a bit
desperate, sorry about that.

anyway, i did try shell directly after what you said, but :(

Dim OldPath As String
Dim NewPath As String
a = 13048
b = "C:\VQ80_2\VQ80RUN" & " """ & a & ".prn""" & " """ & a & ".out"""

ret = Shell(b)

it comes up with an error message stating file not found, but i have checked
the file path, dont know why its not working.

if i was to type it in by myself in dos, it would be like,

c:\VQ80_2\VQ80RUN 13038.prn 13048.out, i am sure that b equals that other
than the double quotations you mentioned, about the file not found, the
13048.prn is the input file, which is under c:\vq80_2, and the 13048.out is
the file the program is supposed to produce in the same folder.
 
J

Jason

another thing, i was just playing with shell, and i found out that its
nothing wrong with the string b, but even just the program without the input
parameters wont run, still comes up with a message file not found.

b = "C:\vq80_2vq80run"
ret = Shell(b)
:(
 
J

Jason

sorry, i did find out why it dint work, dnt bother replying, thank you very
much for your help, it was so simple at the end..:)
 
B

Bernie Deitrick

Jason,

Since the folder is

C:\VQ80_2\

Have you tried:

b = "C:\vq80_2\vq80run"
ret = Shell(b)

Also, have you tried:

ret = Shell("c:\VQ80_2\VQ80RUN 13038.prn 13048.out")

HTH,
Bernie
MS Excel MVP
 
B

Bernie Deitrick

Jason,

Come on - you can't leave us hanging.... what was the simple solution?

Bernie
MS Excel MVP
 
D

Dave Peterson

You have another response at your earlier thread.
this is just an example i am using to point out, i am trying to open command
prompt, and run something in it from vba.

Private Sub cmd1_Click()
Dim OldPath As String
Dim NewPath As String
a = 13048
b = " VQRUN" & " " & a & ".prn" & " " & a & ".out"
'vqrun is the name of the program that i wanted to run in command prompt
'and 13048.prn and 13048.out are the parameters passed to the application
vqrun.

OldPath = CurDir
NewPath = "C:\VQ80_2\ "
ChDrive NewPath
ChDir NewPath

', now, it opens the cmd prompt with the new path, which is fine(c:\vq80_2),
but now i need to run 'vqrun along wit the parameters'.

i know that the below line is wrong because i cannot simply add 'b', but is
there anyway i could do this?
ret = Shell("c:\winnt\system32\cmd.exe", b)

anyhelp on this is much much appreciated because i have been waiting for the
answer of this question for a long time. cheers.
 
J

Jason

sorry bernie, the simple solution is your solution. i had no idea why it did
not work for sometime, i was playing with it for a while, and it worked!, :),
thanks Bernie, and Dave.
 

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

Top