Jump to content

Recommended Posts

Posted (edited)

[sOLVED see my second post]

After much reading I still can't figure out how to run an excel macro.

here is my problem

1-excel book1 already open

2-personal.xls (with several macros in it) running in the background as add-in (invisible)

3-autoit should call macro "compare_files" in module 4 of personal.xls and run it in "book1"

I try some code found here but get an error (see below)

---------------------------------------------

WinActivate("Microsoft Excel - Book1")

WinWaitActive("Microsoft Excel - Book1")

Dim $objXL

$objXL = ObjCreate("Excel.Application")

With $objXL

.Visible = True

$x = .Run("compare_files")

EndWith

---------------------------------

the run function returns an "error in expression"

I think "Run" can't find the macro but I have no idea as to how to point in the right direction.

please help and thanks in advance

Edited by alram
Posted

After much reading I still can't figure out how to run an excel macro.

here is my problem

1-excel book1 already open

2-personal.xls (with several macros in it) running in the background as add-in (invisible)

3-autoit should call macro "compare_files" in module 4 of personal.xls and run it in "book1"

I try some code found here but get an error (see below)

---------------------------------------------

WinActivate("Microsoft Excel - Book1")

WinWaitActive("Microsoft Excel - Book1")

Dim $objXL

$objXL = ObjCreate("Excel.Application")

With $objXL

.Visible = True

$x = .Run("compare_files")

EndWith

---------------------------------

the run function returns an "error in expression"

I think "Run" can't find the macro but I have no idea as to how to point in the right direction.

please help and thanks in advance

this UDF works quite well. I use it at work to automate some Excel workbooks..

if you just want to write a few COM functions i sugest you look at the source for this UDF... should point you in the right direction

http://www.autoitscript.com/forum/index.ph...mp;hl=excel+udf

Posted

thank you guys

I found the solution before your posts and is quite simple

anyway is much appreciated and now, with your posts, I can learn more about COM's for Excel

-------------------------------------------------------------

AutoItSetOption("WinTitleMatchMode", 2) ;match any substring in window title

WinActivate("Microsoft Excel")

WinWaitActive("Microsoft Excel")

If WinActive("Microsoft Excel") Then

Dim $objXL

$objXL = ObjGet("", "Excel.Application")

With $objXL

.Visible = True

$x = .Run("'C:\Documents and Settings\Al User\Application Data\Microsoft\Excel\XLSTART\PERSONAL.XLS'!module4.compare_files")

EndWith

EndIf

--------------------------------------------------------------------

thanks again Al

  • 4 years later...
Posted

Hey theAutoitSpammer

I am also in need of the same situation of running a macro of Book2 on Book1.

When i ran your above code, I am getting the following error.

Can you please help?

Global $ExcelReport = $BaseDir & "STA_Market_weekly_report_master.xlsx"
 
$oExcel1 = _ExcelBookOpen($ExcelReport,1)_ExcelSheetActivate($oExcel1,"NV 
STA")$oExcel1.run("C:\Users\s.mailappan\Desktop\3G-Reports\week_module.xlsm!A1__Market_Summary") ;*Note:* week_module.xlsm is the second Book 

post-79561-0-81737100-1374272987_thumb.p

Posted

This is a 5 year old thread, I don't know the poster you asked, but I don't think he's been around much lately.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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
×
×
  • Create New...