execute a .bat file from inside excel

Detlef 20 Reputation points
2025-12-16T20:43:02.0366667+00:00

how do you open and run a .bat file from inside excel

Microsoft 365 and Office | Excel | For education | Windows
0 comments No comments
{count} votes

Answer accepted by question author
  1. Q&A Assist
    2025-12-16T20:43:12.4266667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To execute a .bat file from inside Excel, you can use VBA (Visual Basic for Applications). Here’s a simple way to do it:

    1. Open Excel and press ALT + F11 to open the VBA editor.
    2. Insert a new module by right-clicking on any of the items in the Project Explorer, selecting Insert, and then Module.
    3. Copy and paste the following code into the module:
         Sub RunBatchFile()
             Dim batFilePath As String
             batFilePath = "C:\path\to\your\file.bat"  ' Change this to your .bat file path
             Shell batFilePath, vbNormalFocus
         End Sub
      
    4. Change the path in batFilePath to the location of your .bat file.
    5. Run the macro by pressing F5 or by going back to Excel, selecting Macros from the Developer tab, and running RunBatchFile.

    This will execute the specified .bat file when the macro is run.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.