PDA

View Full Version : Macro for executing commands from cmd prompt



nemaded
12-10-2016, 03:34 AM
Macro for executing commands from cmd prompt




I need to run a batch from command prompt. It has exe file as well. My moto is to activate exe as schedule run. Below are the problem which I am facing due to which I need a macro to be created. Any of the resolution can solve my problem.


This batch works fine when I directly double click on exe and start it. Also is works fine when manually trigger from command prompt.


Brief idea of Batch - When I double click on batch exe, one csv file is created at given location, ertract all information in string from application and save it in created csv file.


I have tried below three approach and issue is that batch is triggered but csv file if not triggered at the start which causes to fail this batch


approach 1 - when I call exe file by "schedule task"
approach 2 - When I call exe file from macro without using cmd
approach 3 - when I call exe file using macro with cmd


Below is the code I have created. Please suggest



Sub Workbook_Open()
Call Shell("cmd.exe /S /K" & "E:\Users\x9nemd\Desktop\R2_Utility\TfsDataExport.exe", vbNormalFocus)
MsgBox ("Extract Run Activated")
End Sub

Kenneth Hobs
12-10-2016, 09:24 AM
It is unclear what your EXE does and what you expect to get from it. I normally just use Shell() without cmd /c. /k just keeps the window open. Does the EXE require additional user interaction?

A Shellwait() may be needed to allow time for EXE to do its thing. http://www.cpearson.com/excel/ShellAndWait.aspx

To run something like that at a scheduled time, Windows Scheduler will suffice. You can set it to run file types like BAT, VBS, WSH, EXE, XLSM and such. For XLSM, I normally add a popup to allow the user to abort running the Open event code.

I suspect that a simple BAT file will suffice but it all depends...

p45cal
12-11-2016, 03:17 AM
wholesale cross posting:
http://www.ozgrid.com/forum/showthread.php?t=202088
http://stackoverflow.com/questions/41074420/macro-for-executing-commands-from-cmd-prompt
https://answers.microsoft.com/en-us/msoffice/forum/msoffice_excel-mso_other/macro-for-executing-commands-from-cmd-prompt/9b5a1dc8-ed3f-464e-85ff-06db4c678a9c
http://www.mrexcel.com/forum/excel-questions/980127-macro-executing-commands-cmd-prompt.html

Aussiebear
12-11-2016, 02:56 PM
@nemaded, apparently you haven't read the forum rules for any of the sites where you cross posted..... Or you have, and are displaying utter arrogance to all those who contribute to the forums. Please correct the situation in all the forums, before continuing with this post.