0

I have a requirement to call 4 vb script files(.vbs) one by one to execute few excel macros.lets say if i click on start button, it will trigger 1st .vbs task and once the 1st .vbs complete then it should move to 2nd .vbs call and it goes on. These all should be triggered by a single button click in web UI. How i can achieve this using nodejs? I have found this below package(using CMD) in the internet but i could not proceed how to achieve this with POST method using submit button and execute vbs files one by one.

const nodeCmd = require('node-cmd');
app.post('/', function (req, res) {


    res.sendFile(__dirname + '/progress.html');
    callvbs();

});
function callvbs()
{

    nodeCmd.get('callvbs.vbs');
    console.log('file created....');

}
user692942
  • 16,398
  • 7
  • 76
  • 175
AtomNew
  • 59
  • 8
  • You could write the excel macros in an actual excel file and run them upon opening the file. That way node just has to open the excel file with office. Alternatively, run the VBA directly using this answer https://stackoverflow.com/questions/47218117/run-vbs-script-with-node – Shilly Jan 24 '20 at 14:17

1 Answers1

0

First of all I am not sure what is full use case to execute vb script during an api call. I wouldn't suggest that. Look for other alternatives. If it is really required. You could use node-cmd with promises. someting like

const Promise = require("bluebird");
const cmd = require("node-cmd");

const getAsync = Promise.promisify(cmd.get, {"multiArgs": true, "context": cmd});

async function callScripts() {
  const script1Response = await getAsync("script1.vbs");
  console.log(script1Response);
  const script2Response = await getAsync("script2.vbs");
  console.log(script2Response);
  const script3Response = await getAsync("script3.vbs");
  console.log(script3Response);
  const script4Response = await getAsync("script4.vbs");
  console.log(script4Response);
}

app.post("/", async (req, res) => {
  await callScripts();
});


Ashish Modi
  • 7,529
  • 2
  • 20
  • 35