Question

I have the following shell code:

RetVal = Shell("""C:\pathforprogram.exe""" + "/argument1 /argument2 /savefile=C:\textfile.txt",1)

My problem is now that i want /argument1 for example to be read from a cell. So if Cell A1 has the following string /DoThis then i would do the following:

ArgumentA = Range("A1").Value

RetVal = Shell("""C:\pathforprogram.exe""" + "ArgumentA /argument2 /savefile=C:\textfile.txt",1)

However i get the following error returned:

ArgumentA is not a valid input command

So it seems that the shell command reads ArgumentA instead of /Dothis.

Is there any solution to this? Thank you.

Était-ce utile?

La solution

Try this one:

ArgumentA = Range("A1").value
RetVal = Shell("""C:\pathforprogram.exe""" & ArgumentA & " /argument2 /savefile=C:\textfile.txt", 1)

also I suggest you to fully qualify your Range object:

ArgumentA = ThisWorkbook.Worksheets("Sheet1").Range("A1").Value
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top