How Can I run a .bat file from Excel?
14,998
You can run a batch file via a macro VBA script. For example:
Sub RunBatch()
Call Shell(Environ$("COMSPEC") & " F:\Financial\Data\Reports\ExpensesYTD\Batch1.bat", vbNormalFocus)
End Sub
You can use a worksheet change event to create a drop down box. Something like below.
Change the range to whichever cell displays the results of the dropdown box, and change the Macro names. Also, this code would be placed in the code for the worksheet, not a new module.
Sub Worksheet_Change(ByVal Target As Range)
Select Case Target.Range("A1").Value
Case "First macro Name"
Call First_Marco
Case "Second macro Name"
Call Second_Marco
Case "Third macro Name"
Call Third_Marco
Case "Fourth macro Name"
Call Fourth_Marco
End Select
End Sub
Author by
niki niki
Updated on June 14, 2022Comments
-
niki niki almost 2 years
I have 5 batch files at different locations and I want to run them through Excel like below:
F:\Financial\Data\Reports\ExpensesYTD Batch1.bat, Batch2.bat, Batch4.bat F:\Financial\Data\Reports\AccountPnlMTD Batch5.bat, Batch6.bat, Batch7.bat
I want to run batch files using excel by a macro..excel macro shuld call the .bat batch files where they are sited and shuld run. Please help me to do this.
-
niki niki almost 11 yearsThx..Dtmland. I want to run by salecting one by one. (In a dropdown box, where I can salet .bat file & can run).