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.

有帮助吗?

解决方案

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top