Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Perl在**已打开**Excel工作簿中运行宏_Perl_Ole_Excel - Fatal编程技术网

如何使用Perl在**已打开**Excel工作簿中运行宏

如何使用Perl在**已打开**Excel工作簿中运行宏,perl,ole,excel,Perl,Ole,Excel,我想使用Perl在已打开的Excel工作簿中运行宏 如果我只想打开工作簿并运行宏,则以下代码有效: #!C:\Perl\bin\perl.exe use strict; use Win32::OLE; my $Excel = Win32::OLE->new('Excel.Application') or die; $Excel->Workbooks->open('M:\Programs\MyExcelFile.xls'); $Excel->run('Book1!

我想使用Perl在已打开的Excel工作簿中运行宏

如果我只想打开工作簿并运行宏,则以下代码有效:

#!C:\Perl\bin\perl.exe    
use strict;
use Win32::OLE;

my $Excel = Win32::OLE->new('Excel.Application') or die;
$Excel->Workbooks->open('M:\Programs\MyExcelFile.xls');
$Excel->run('Book1!ChartData');
$Excel->quit;

但是如何在打开的工作簿上操作呢?

使用
GetActiveObject
。发件人:

Here is a simple Microsoft Excel application.

        use Win32::OLE;

        # use existing instance if Excel is already running
        eval {$ex = Win32::OLE->GetActiveObject('Excel.Application')};
        die "Excel not installed" if $@;
        unless (defined $ex) {
            $ex = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;})
                    or die "Oops, cannot start Excel";
        }