Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Run Excel Macro


  • Please log in to reply
3 replies to this topic

#1 Tstudent

Tstudent

    Seeker

  • Active Members
  • 11 posts

Posted 17 March 2012 - 10:52 AM

What i would like to do is:

1) Open an excel file // no problem, this is very simple
2) wait for excel file completely load // i can use sleep function and use a very long time to be sure
3) run an excel macro called "mymacro1" // i don't know how to do this

Can you give me the correct sintax for point three?

thank you







#2 JoHanatCent

JoHanatCent

    Just for Fun

  • Active Members
  • PipPipPipPipPipPip
  • 402 posts

Posted 17 March 2012 - 11:12 AM

If you use the following you do not have to build a sleep in:
#include <Excel.au3>
and to open use
$oExcel = _ExcelBookOpen($file, 1)

$oExcel.run("mymacro1");<<<< == Your Macro to run
Posted Image

#3 Tstudent

Tstudent

    Seeker

  • Active Members
  • 11 posts

Posted 17 March 2012 - 04:51 PM

Thank you very much.

I have another question, don't know if it is possible.
Before run excel file i want (with _ExcelBookOpen($file, 1)) i want to check if, accidentally, there are other excel files already open. In that case i want close all of them (saving before exit).
Is possible to do this check and close all other excel files eventually opened?

Thanks

#4 Tstudent

Tstudent

    Seeker

  • Active Members
  • 11 posts

Posted 17 March 2012 - 05:53 PM

Found the solution.

Paste here for other interested users of this beautiful forum:

$oExcel = ObjGet("", "Excel.Application")
For $element In $oExcel.Application.Workbooks
If $element.FullName <> "" Then
MsgBox(0,"",$element.FullName)
$element.Save
$element.Close
Else
$element.Activate
$oExcel.Application.Dialogs(5).Show
EndIf
Next
$oExcel.Application.Quit




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users