VBA WScript stopped working

The following code worked fine yesterday, but not today.
The file "Swiss_rob.bat" does get updated.
If I go to "File Explorer", and double-click "Swiss_rob.bat", it runs fine.


Sub Swiss()

    Dim OutputPath As String
    Dim objShell

    OutputPath = ThisWorkbook.Path
    
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set a = fs.CreateTextFile(OutputPath & "\Swiss_rob.bat", True)
    a.writeline Range("Command")
    a.Close
    Set objShell = CreateObject("WScript.Shell")
    cmd = OutputPath & "\Swiss_rob.bat"

    result = objShell.Run(Chr(34) & cmd & Chr(34), 1, True)
    Set objShell = Nothing

End Sub

Open in new window

rrhandle8Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieAnalyst Assistant Commented:
How is not working now?
0
rrhandle8Author Commented:
Line 13 or 15 is not doing anything.
The result.txt file does not change.
0
Bill PrewIT / Software Engineering ConsultantCommented:
The code looks okay, what is the exact contents of the Command defined range?


»bp
0
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

rrhandle8Author Commented:
swetest -p4 -b1.1.2017 -n4000 -s1 -g, -fTjPlsbd -head -true > results.txt

If I double-click on the .bat file which contains the above, everything works fine, but not if I run the macro.
The macro use to work fine.
The macro successfully updates the .bat file, but does not run the .bat file
Thank you
0
Bill PrewIT / Software Engineering ConsultantCommented:
Okay, I would approach it this way.

Add a PAUSE to the end of the BAT file (you will need to add that to the "Command" range so it gets written to the BAT file.  That way when it runs you can look at the DOS window for any messages.

Also, check the return code from the .Run() method, what does it contain after the execution of the BAT file?

Make sure there is not an "ON ERROR RESUME NEXT" active when the code runs, you want to see any VBA errors thrown.

Debug through the code line by line, check all variables as they are assigned to make sure they are what you are expecting.  And look at the command window when the PAUSE occurs to see if any errors are generated there.  Also make sure that it is running in the same current working directory as where the BAT file exists, it could be the results.txt file is getting written to a different folder than you think.


»bp
0
rrhandle8Author Commented:
Ah, there is a problem.  'swetest' is not recognized as an internal or external command, operable program or batch file.
0
Bill PrewIT / Software Engineering ConsultantCommented:
Makes sense, but not sure why you didn't get that error running the BAT.  Unless the BAT you ran then was in the same folder as the EXE.

At any rate, I'd say you have a few choices:
  1. Copy the EXE where the BAT will be.
  2. Add the folder where the EXE exists to the PATH
  3. Fully qualify the path to the EXE in the BAT
  4. In the BAT, add a line to CD to the directory where the EXE is before running it


»bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rrhandle8Author Commented:
I tried everything you suggested. No help. Had to leave for awhile. Left computer running. Came back. It still did not work. I created another workbook. Did not work. Went back to the original workbook. IT WORKS AGAIN!? Don't have a clue what happened, but I thank you for your effort.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.