Jump to content
Sign in to follow this  
gauravvogue

how to run macro using autoit

Recommended Posts

gauravvogue

hi.. i have two queries

1... How to run macro using autoit?

I have used the below code but its giving error as unable to parse line......is that the right code ? I am opening a macro file name"Tmacro" saved in C drive folder named Market

 

$oExcel = ObjCreate("Excel.Application")
$oExcel.WorkBooks.Open($C:MarketTmacro.xlsm)
$oExcel.Run("Macro1")
"more code"

 

2. Whenever the macro execution gets completed then i want to execute further commands in my autoit script and dont want to use sleep function?????? please help

Share this post


Link to post
Share on other sites
water

Needs to be:

$oExcel.WorkBooks.Open("C:\Market\Tmacro.xlsm")

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

Doesn't "Run" wait until the called macro has finished? So you simply call "Run" multiple times in your AutoIt script.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
gauravvogue

hi

i have used the below command to open my excel macro file

_ExcelBookOpen ("C:MarketTmacro.xlsm")( getting successful)

 

but can u tell me how would i run my macro from here... as i have used

.Run("Macro1")  but it is showing an error as object referenced outside a "with " statement

Share this post


Link to post
Share on other sites
water

$oExcel = _ExcelBookOpen ("C:\Market\Tmacro.xlsm")
$oExcel.Run("Macro1")
$oExcel.Run("Macro2")
...

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
gauravvogue

thanks sir!

It was getting successful. Just one last query

How can i program that" I want to wait until the macro gets finished"........?

actually i dont want to include" SLEEP command"..................

 

sometimes macro run 30 seconds and sometimes 50 seconds......

Share this post


Link to post
Share on other sites
water

MSDN says: "The Run method returns whatever the called macro returns"

So I think the AutoIt script will wait until the macro has finished and then processes the next statement.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×