• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 486
  • Last Modified:

How to run macro by using batch file?


I have one excel. It contains macro.. i would like to run macro when the batch file clicked.. is there any way to run macro by using batch file??
venkatesh ks
venkatesh ks
2 Solutions

pls try

'Your .bat
WScript "D:\YourFolder\yourfile.vbs"

Open in new window

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("yourXLfile.xls")

'objExcel.Application.Visible = True

objExcel.Application.Run "Macro.TestMacro()"
objExcel.ActiveWorkbook.Close '(False)

WScript.Echo "Finished."

Open in new window

Saqib Husain, SyedEngineerCommented:
One way is to  configure excel to load the macro file as excel is opened. That macro file shall have to be placed in the XLSTART folder and  can contain an autorun macro. All the batch file will have to do is load excel and the macro can take care of the rest.
venkatesh ksAuthor Commented:
Hi Rgonzo1971,

I ran ur code,. But it show as run time error like  ," The macro may not be available in this workbook or all macros may be disabled.  Error code like "800A03EC"..."

I don't know how to solve it..

Advance thanks..
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

the user should hot have to click enable macros to be able to run it automatically
venkatesh ksAuthor Commented:
Hi Rgonzo1971,
I am not getting ur last answer.. please elaborate it..
When you open a xlsm file do you have to enable the macros?
venkatesh ksAuthor Commented:
I saved a macro as independent.. I would like to use that macro for every workbook,.. or what workbook i like..
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

-- Rgonzo1971 (https:#a41873476)
-- Rgonzo1971 (https:#a41873774)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

Experts-Exchange Cleanup Volunteer
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now