Solved

How to run macro by using batch file?

Posted on 2016-11-03
8
32 Views
Last Modified: 2016-12-01
Hi,

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??
0
Comment
Question by:venkatesh ks
8 Comments
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 41873476
HI,

pls try

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

Open in new window



'YourFile.vbs
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)


objExcel.Application.Quit
WScript.Echo "Finished."
WScript.Quit

Open in new window

Regards
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 41873480
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.
0
 

Author Comment

by:venkatesh ks
ID: 41873744
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..
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 49

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 500 total points
ID: 41873774
the user should hot have to click enable macros to be able to run it automatically
0
 

Author Comment

by:venkatesh ks
ID: 41873777
Hi Rgonzo1971,
 
I am not getting ur last answer.. please elaborate it..
0
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 41873844
When you open a xlsm file do you have to enable the macros?
0
 

Author Comment

by:venkatesh ks
ID: 41873895
I saved a macro as independent.. I would like to use that macro for every workbook,.. or what workbook i like..
0
 
LVL 14

Expert Comment

by:frankhelk
ID: 41908417
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:

Split:
-- 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.

frankhelk
Experts-Exchange Cleanup Volunteer
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question