(Using Win32:OLE
w/ Perl)
Is there a way to specify which workbook an Excel macro is run from if multiple workbooks are already open?
I am using the following code, but it sometimes fails if more than one Excel workbook is open. I know there is an obvious solution to just close the other workbooks, but my work often involves using another Excel workbook (which is a hassle to keep closing and reopening). So I am hoping there is a way to specify which workbook to run the macro from (perhaps similar to how one specifies an additional parameter such as the title for Win32::GUI
).
Here is an example of what currently just works with one workbook open:
use Win32::OLE;
my $excel = Win32::OLE->GetActiveObject('Excel.Application');
$excel->Run("macroName");
The macro I am running exports all the sheets of the current workbook, so it is important that it is run from the correct workbook. I checked out this question (How do I use Perl to run a macro in an **already open** Excel workbook) but it doesn't seem to address how to select which macro the workbook is run from.
I was also reading through this article (http://docs.activestate.com/activeperl/5.6/faq/Windows/ActivePerl-Winfaq12.html), but it didn't seem to show a way how to run a macro from a specific workbook. Thinking a bit more, I could see not being able to specify which workbook to run from being an issue if two workbooks have the same macro name, but for some reason, these do different things.
Any suggestions?
$Excel->Workbooks->open('c:\somefile.xls');
– mrbungle