Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am working on VBA, from which I have to call a vbscript by passing some values.

Here is the code:

''VBA
'Below values are on different cells of Excel file which I am reading 
'into a global variable then pass it to vbscript.
'SFilename = VBscript file path
'QClogin = "abc"
'QCpassword = "abc"
'sDomain = "xyz"
'sProject = "xyz123"
'testPathALM = "Subject\xyz - Use it!\xyz_abc"
'QCurl = "http://xxx_yyy_zzz/qcbin/"
Set wshShell = CreateObject("Wscript.Shell")

Set proc = wshShell.exec("wscript " & SFilename & " " & QClogin & _
" " & "" & QCpassword & " " & "" & sDomain & " " & "" & sProject & _
" " & "" & testPathALM & " " & "" & QCurl & "")

''VBscript on some location
Dim strUserName, strPassword, strServer
strUserName = WScript.Arguments(0)  '"abc"
Msgbox "strUserName : " & strUserName
strPassword = WScript.Arguments(1)  '"abc"
Msgbox "strPassword : " & strPassword
strServer = WScript.Arguments(5)    '"http://xxx_yyy_zzz/qcbin/"
Msgbox "strServer : " & strServer

Dim strDomain, strProject, strRootNode
strDomain = WScript.Arguments(2)    '"xyz"
Msgbox "strDomain: " & strDomain
strProject = WScript.Arguments(3)   '"xyz123"
Msgbox "strProject: " & strProject
strRootNode = WScript.Arguments(4)  '"Subject\xyz - Use it!\xyz_abc"
Msgbox "strRootNode: " & strRootNode

Now, when I running the code, it is passing below values properly to vbscript:

QClogin = "abc"
QCpassword = "abc"
sDomain = "xyz"
sProject = "xyz123"

It is having issues with these:

testPathALM = "Subject\xyz - Use it!\xyz_abc"
QCurl = "http://xxx_yyy_zzz/qcbin/"

Now, wierd thing for me is, if I keep a cell empty for "testPathALM" which is having "Subject\xyz - Use it!\xyz_abc" as value, I am getting "QCurl" value properly in vbscript.

But, if I keep value "Subject\xyz - Use it!\xyz_abc" for "testPathALM", then I am getting "-" for strServer which suppose to be "QCurl" value and "Subject\xyz" for "strRootNode" which supposed to be "Subject\xyz - Use it!\xyz_abc".

I am unable to understand what is the issue here.

Thanks a ton in advance.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

Safer to quote all of your parameters:

Set wshShell = CreateObject("Wscript.Shell")
Set proc = wshShell.exec("wscript """ & SFilename & """ """ & _
                         QClogin & """ """ & QCpassword & """ """ & _
                         sDomain & """ """ & sProject   & """ """ & _
                         testPathALM & """ """ & QCurl & """")

Try a debug.print to make sure it looks as it should...

share|improve this answer
    
+ 1 you beat me to it :) –  Siddharth Rout Sep 16 '13 at 17:52
    
Thanks a lot @Tim, you are life saver... I don't know how I missed that... –  Nelly27281 Sep 16 '13 at 17:57
1  
Thanks @Siddharth... –  Nelly27281 Sep 16 '13 at 18:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.