Jump to content

Excel Macros?


Recommended Posts

it's more of an excel question, but since I'm using autoit, I thought I'd take to the popular course and ask it here... I've got an excel sheet that has a big pretty button that I need to click as the last step of a script that downloads some data and runs another application (SAS) to generate some CSV files that this excel file needs... Anyways, back to the button, big button, size of texas, but the excel file might not be open to that sheet, yada yada, how to I launch the macro automatically? I don't want it to happen every time the workbook is opened, just when I'm opening it with my AutoIt script, the users can launch it manually if they want to recalculate on their own...

any ideas?

"I'm not even supposed to be here today!" -Dante (Hicks)

Link to comment
Share on other sites

Re: Just clicking: well, I'm worried about window position, if the excel file's on the wrong sheet, etcetera, all of which I can't seem to determine with AU3_Spy ... or if one user opening it has their excel toolbars filling the excel window down to where the button is on someone else's... I'd like to do a controlclick, but the button doesn't display anything in "last control under mouse"...

Re: order of execution: I am opening the Excel file, so the user can click it, I am trying to see if anyone knows how to make excel launch a macro from that point... I tried Send("!{F8}") which is how you can manually open the "Macros" window, but it doesn't open the window. I suspect that Excel captures this to avoid malicous code from executing the dialog...

"I'm not even supposed to be here today!" -Dante (Hicks)

Link to comment
Share on other sites

On My machine (WinXP, OfficeXP) I did this simple macro and it worked fine:

winactivate("Microsoft Excel")
send("!{f8}")

brought up the macro window.

Alternately, I set the macro I wanted at ^w and simply sent ^w to that window and it worked flawlessly as well. I also didn't have to try and set what macro to run this way.

Since macros have hotkeys as well, I would suggest using them on automation.

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

If you assign the item to a text button you can alt-select it and enter to execute the macro.

Use the answer wizard on word autoexec to see various ways to start Excel.

awesome, I followed these directions... (yeah, this is me, looking at the Excel helpfile :D ) and it works just fine...

Start a macro from a keyboard shortcut

On the Tools menu, point to Macro, and then click Macros.

In the Macro name box, enter the name of the macro (macro: An action or a set of actions you can use to automate tasks. Macros are recorded in the Visual Basic for Applications programming language.) you want to assign to a keyboard shortcut key (shortcut key: A function key or key combination, such as F5 or CTRL+A, that you use to carry out a menu command. In contrast, an access key is a key combination, such as ALT+F, that moves the focus to a menu, command, or control.).

Click Options.

If you want to run the macro by pressing a keyboard shortcut key (shortcut key: A function key or key combination, such as F5 or CTRL+A, that you use to carry out a menu command. In contrast, an access key is a key combination, such as ALT+F, that moves the focus to a menu, command, or control.), enter a letter in the Shortcut key box. You can use CTRL+ letter (for lowercase letters) or CTRL+SHIFT+ letter (for uppercase letters), where letter is any letter key on the keyboard. The shortcut key letter you use cannot be a number or special character such as @ or #.

NoteĀ  The shortcut key will override any equivalent default Microsoft Excel shortcut keys while the workbook that contains the macro is open.

If you want to include a description of the macro, type it in the Description box.

Click OK.

Click Cancel.

"I'm not even supposed to be here today!" -Dante (Hicks)

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...