PDA

View Full Version : Send VBS to command line problem



nelson
2009-05-14, 07:52 PM
I'm not sure what I'm doing wrong, maybe someone can help me. I'm trying to send this to the command line and run the script. I had it running but got pulled off and overwrote my dvb file!

Here is the what I have


Private Sub YesButton_Click()
Set WshShell = CreateObject("WScript.Shell")
ThisDrawing.SendCommand((startapp "wscript" "\" "x:\\Network\\Version\\vba\\launch.vbs")
End Sub
I keep getting "Compile Error Expected: )"

I have something in the wrong place or order I know.

Ed Jobe
2009-05-14, 10:21 PM
You have several problems from trying to mix api's. First, you create a shell but don't use it. You could run the vbs from that object, instead you're trying to run it from the command line. Second, (startapp) is a lisp function that does the same thing as SendCommand. You don't need it. Third, SendCommand's argument is a single string. If you need to have command line arguments that require quotes, then you have to use an esc char for those quotes.

RobertB
2009-05-16, 12:59 AM
You have several problems from trying to mix api's. First, you create a shell but don't use it. You could run the vbs from that object, instead you're trying to run it from the command line. Second, (startapp) is a lisp function that does the same thing as SendCommand. You don't need it. Third, SendCommand's argument is a single string. If you need to have command line arguments that require quotes, then you have to use an esc char for those quotes.And finally, there are two opening parens in the last statement, but only one closing paren.

nelson
2009-05-20, 02:15 PM
I found the problem.
I don't want to have to support a VBS to use outside CAD for system build use, and a set of VBA for inside. That's why I want to have one script that I can launch either way, and is consistent to how we have most our code. I have one that looks for the connection to the network and switches to offline mode, and this script that copies down all custom code and standard files from the network to the local "network" folder on the laptop. All that this is doing is sending the VBS to the command line and running it.

The problem was that the SendCommand wants a String value, and I didn't set my command in a String. Below works just fine.


Dim CmdString As String
CmdString = "(startapp ""wscript"" ""\ X:\\Network\\version\\vba\\CADupdate.vbs"")"

Me.Hide

Set WshShell = CreateObject("WScript.Shell")
ThisDrawing.SendCommand CmdString & vbCr

I don't see another way to launch a script in vba. Do either of you have a suggestion?

Ed Jobe
2009-05-20, 05:40 PM
As I mentioned before, you create WshShell but don't use it. Use the scripting host to run scripts. When you use startapp, it just sends the string to a windows command line and the os recognizes the vbs extension. In vba you can cut out the middle man and use the object you created to run the script directly.