Macro for executing commands from cmd prompt

nemadedurgesh

New Member
Joined
Dec 2, 2016
Messages
5
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
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
The workbook_open event procedure needs the word Private included and it must be installed in the ThisWorkbook code module. Press Alt + F11 to open the VB editor, then double click on "ThisWorkbook" in the small Projects pane at upper left of the large code pane. When you see [ThisWorkbook(Code)] at the top margin of the VB editor window, paste your code into the large code pane and click the 'Save' icon. Close the file and reopen it and your code should run.
Code:
Private Sub Workbook_Open()

As written, you message box will not appear until yourbatch file has executed.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,874
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top