Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7973497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:07:19+00:00 2026-06-04T08:07:19+00:00

I have a batch file that does several things and the last step is

  • 0

I have a batch file that does several things and the last step is to open an excel document and run the macro contained in it which updates the contents of the file. The macro runs perfectly with the click of a button but I want it all to be done when you run the .bat file.

I know I could attach the macro to the open event so it runs when you open the macro but I only want it to update automatically when you run the bat file, not every time you open the thing.

Maybe I could pass a parameter to let it know that it’s been run from a .bat? or run it directly with an excel command?

like this?
run excel.exe /runMacro "mymacro"   

I can’t find what I need anywhere, thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:07:21+00:00Added an answer on June 4, 2026 at 8:07 am

    Yes, basically the easy way is to move the contents of your “mymacro” into your ThisWorkBook

    Private Sub Workbook_Open()
    

    With security, the user may still have to click the enable macros button unless you want this to be unattended. If you want to pass arguments into the workbook open, then you can do this by parsing the command line. You can search code examples on Google for “excel GetCommandLineW”

    Private Declare Function GetCommandLine Lib "kernel32" Alias "GetCommandLineW" () As Long
    Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (MyDest As Any, MySource As Any, ByVal MySize As Long)
    
    Function CmdToSTr(cmd As Long) As String
    Dim Buffer() As Byte
    Dim StrLen As Long
        If cmd Then
        StrLen = lstrlenW(cmd) * 2
        If StrLen Then
            ReDim Buffer(0 To (StrLen - 1)) As Byte
            CopyMemory Buffer(0), ByVal cmd, StrLen
            CmdToSTr = Buffer
            End If
        End If
    
    End Function
    
    Private Sub Workbook_Open()
        Dim CmdRaw As Long
        Dim CmdLine As String
        CmdRaw = GetCommandLine
        CmdLine = CmdToSTr(CmdRaw)
        ' From here you can parse the CmdLine
        ' ...snip...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several batch files that I call from a parent batch file. I
I have a batch file in DOS that does some checking and I need
I have a batch file that does the following: @IF EXIST C:\Program Files\MyAppFolder (
I have steps in the batch job that does different things. But before I
I have a batch file that does a lot of stuff, then at the
I have a windows batch file that does this: for %%s in (*.sql) do
I have a batch file that installs WinVNC in about 1 second and starts
I have a batch file that is running inside CruiseControl and outputing either Pass
I have a batch file that will detect if the user has the .Net
I have a batch file that is located on one machine that I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.