0

Okay so this might be a little bit different. First I will start by stating my personal case the i will broaden it. I am Using robot framework with python. So i have a text file that has all the commands i want it to do. So to run the command, I go to my CMD and type " pybot NameOfFile.txt " that runs the robot framework commands. I am going to make a presentation of this. So i want to run the command by just clicking a "Command button" on the developer tools in Excel. Or any other way really. So far, no luck. Please if anyone can help me out that would be fantastic.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
Diego Gomez
  • 33
  • 2
  • 2
  • 6

2 Answers2

0

This can be achieved by using Shell(commandline) in VBA. Be aware that it will require full path and filename for your pybot executable and the argument (txt file). See How can I execute a shell command using VBA?

A possible call would look like Shell(chr(34) & "c:\path\to\py\pybot.exe" & chr(34) & " " & chr(34) & "c:\file name with spaces.txt" & chr(34)).

Community
  • 1
  • 1
MP24
  • 3,110
  • 21
  • 23
  • Its probably alot to ask, but can you try to give me a spcific example? – Diego Gomez Aug 13 '14 at 18:46
  • How would i add the filename from my pybot in the command line? – Diego Gomez Aug 13 '14 at 19:10
  • Did you check the link (answer two) for an example? Would be something like `Shell(chr(34) & "c:\path\to\py\pybot.exe" & chr(34) & " " & chr(34) & "c:\file name with spaces.txt" & chr(34))`. – MP24 Aug 13 '14 at 19:15
  • Public Sub Display_CMD() Shell(C:\Users\cwr.Diego.Gomez\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 2.7.exe" & chr(34) & " " & chr(34) & "c:\Diego.txt" & chr(34)) End Sub – Diego Gomez Aug 13 '14 at 19:23
  • Missing `"` (and chr(34)) at the start of the command. Anyway, I doubt that this is the correct path to your python exe. – MP24 Aug 13 '14 at 19:28
  • Shell (Chr(34) & "C:\Python27.exe" & Chr(34) & " " & Chr(34) & "C:\Users\cwr.Diego.Gomez\Desktop\main_test_suite\myTests\Diego.txt" & Chr(34)) ... sould be working better but now its telling me chr(34) *the first one* is an invalid outside procedure – Diego Gomez Aug 13 '14 at 19:40
0

Try

Shell ("cmd /C ""start pybot NameOfFile.txt""")

Greetings

Axel

Axel Richter
  • 56,077
  • 6
  • 60
  • 87
  • omg dude that is exactly what i need! but the CMD has to be started from a specific file. i tried this -- Private Sub CommandButton1_Click() Shell ("cmd /C:\Users\cwr.Diego.Gomez\Desktop\main_test_suite\myTests ""start pybot Diego.txt""") End Sub – Diego Gomez Aug 14 '14 at 12:42
  • when i run it nothin happens – Diego Gomez Aug 14 '14 at 13:00
  • Nothing happens? Hm. What happens if you try `Shell ("cmd /K ""start pybot --version""")`? Note the /K, so the CMD remains open. – Axel Richter Aug 15 '14 at 04:46
  • the original one you put works like a charm. Its just that when I try to put my own path that i want the cmd to open in --as i showed above -- nothig happens. so i was wondering if there is a specific way t file a specific path – Diego Gomez Aug 15 '14 at 12:36
  • `Shell ("cmd /C ""cd ""P:\Test\"" && start pybot ""P:Neu Textdokument.txt""""")` warrantless without legal ;-) In cd-part the full path, in start part only the drive. – Axel Richter Aug 15 '14 at 13:18
  • You sir, are a God among men. Thanks a bunch – Diego Gomez Aug 15 '14 at 15:52