Solved

How to run macro by using batch file?

Posted on 2016-11-03
8
21 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 48

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
 
LVL 48

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

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

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 13

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now