Jump to content

Running an excel macro from within AutoIt


mikep56
 Share

Recommended Posts

Hi All,

I have been struggling to figure out how to run an Excel macro on an Excel spreadsheet from an AutoIt script. I have looked over the forum and the help files without success.

Thanks for any help that can be tossed my way.

Regards,

Mike

Link to comment
Share on other sites

Hi All,

I have been struggling to figure out how to run an Excel macro on an Excel spreadsheet from an AutoIt script. I have looked over the forum and the help files without success.

Thanks for any help that can be tossed my way.

Regards,

Mike

Is it associated with a hotkey? Might be as easy as ControlSend() the hotkey to the Excel window.

<_<

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Hi PsaltyDS,

The macro is launched by pressing a smiley face button that I placed on the toolbar that is associated with the macro. However, being in VB or VBS or VBA (I can't remember which), shouldn't the macro be launchable from an AutoIt script command. Right now I am using the mouse commands to click on the smiley face.

Thanks for your help.

regards,

Mike

Link to comment
Share on other sites

Link to comment
Share on other sites

@all

Maybe this can help you out.

switches for Excel

You can use a command line switch /m to activate a makro.

Option 2 is this : Run Excel Macros through Automation

regards

ptrex

The references on Option 2 imply that you can only do four specific built-in macros that way: xlAutoActivate, xlAutoClose,

xlAutoDeactivate, and xlAutoOpen. Does that work with ad hoc macros of your own?

<_<

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Hi All,

After some deep internet searching, I found this simple way. Open the PERSONAL.XLS file in Excel. Right click the sheet1 tab at the bottom and select View Code. In the Project box on the left, click on ThisWorkbook. Then at the top left pulldown select Workbook, and type in Run "name of macro" between Private Sub Workbook_Open() and End Sub. Make sure that the macro name is in quotes. Then click on File, Save Personal.XLS. The next time you open Excel, the macro will run.

Good luck and thanks again to all in this forum who helped.

Regards,

Mike

Link to comment
Share on other sites

@PsaltyDS

Yes works fine for any macro.

; AutoRun Macro

Dim $objXL

$objXL = ObjCreate("Excel.Application")
  
    With $objXL.Application
        .Visible = True
        ;Open the Workbook
        .Workbooks.Open ("C:\Test.xls")
        $x = .Run("Test") ; MacroName, Parameters1, Parameter2, ...
    EndWith

Regards

ptrex

Link to comment
Share on other sites

@PsaltyDS

Yes works fine for any macro.

; AutoRun Macro

Dim $objXL

$objXL = ObjCreate("Excel.Application")
  
    With $objXL.Application
        .Visible = True
        ;Open the Workbook
        .Workbooks.Open ("C:\Test.xls")
        $x = .Run("Test") ; MacroName, Parameters1, Parameter2, ...
    EndWith

Regards

ptrex

Coolness! <_<

Thanks for the tip.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...