(Please forgive my ignorance on Excel add-ins, and feel free to correct my teminology where appropriate.)
I have an Excel add-in that is used regularly. This add-in inserts a toolbar with a number of buttons. I want to automate the task of opening a spreadsheet in Excel and then "clicking" one of those buttons. In other words, I want to use Perl (or the command line) to activate a particular function of this add-in.
I do not have immediate access to the source code for the add-in, but I should be able to request specific information such as procedure names if required.
I cannot use CPAN modules for this task—only what is installed with my version of ActivePerl—but I do have Win32::OLE, which has been helpful for other Office automation.
Any pointers?
Is there a key binding for the toolbar button?
If there is, you could use the SendKeys method to send that key to Excel: http://msdn.microsoft.com/en-us/library/aa202943(office.10).aspx
Alternatively, the CommandBars collection might be useful. See http://msdn.microsoft.com/en-us/library/aa171356(office.11).aspx for reference.
The sample code below lists the visible command bars and the controls in the 'Standard' toolbar. When it finds a control with the caption Open, it invokes the control. This should display the "File -> Open" dialog:
HTH
I don't know how you would go about clicking one of those buttons.
But I might have a workaround. If you can create a macro in excel to press the button calling that macro from perl is possible.
Untested!
More tips at http://www.perlmonks.org/?node_id=153486
I think you're on the right track within Win32::OLE. I've used it to automate working with Excel in the past. I don't believe that OLE gives you access to GUI elements (e.g. activating a button press) so you'll probably need to find out whether or not the toolbar supports OLE and what the interface is.
The other alternative I can think of would be to try programmatically control the mouse to actually click the button. That assumes that you're running OLE with Excel visible (it doesn't have to be) and creates the difficult situation of figuring out how to position the cursor. OLE would be much simpler if it's an option.