Win::OLE excel function run twice

J

Jason Chen

I have an excel macro in file c:\temp\test1.xls as this:

Public Function test1(str As String)
Debug.Print "the string is: " & str
End Function

I run the macro through perl like this:

use Win32::OLE;
my $Excel = Win32::OLE->GetActiveObject('Excel.Application');
my $Book = $Excel->Workbooks->Open("C:\\temp\\test1.xls");
$Excel->Run('Test1("kabc")');

Here is Result:

here is kabc
here is kabc

The problem is the test1 function is run TWICE!!!

I am using Windows 2000 and ActivateState Perl 5.6.

Help!
 
B

Brian Helterline

Jason Chen said:
I have an excel macro in file c:\temp\test1.xls as this:

Public Function test1(str As String)
Debug.Print "the string is: " & str
End Function

I run the macro through perl like this:

use Win32::OLE;
my $Excel = Win32::OLE->GetActiveObject('Excel.Application');
my $Book = $Excel->Workbooks->Open("C:\\temp\\test1.xls");
$Excel->Run('Test1("kabc")');

Wrong syntax. See the Excel docs for the Run command.
Arg0 = macro name, Arg1...n = arguments. Try:
$Excel->Run( 'Test1', "kabc");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,817
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top