http://qs321.pair.com?node_id=11147359


in reply to Perl vith VBA macros with arguments

I created a macro-enabled spreadsheet which had the following VBA:
Public Function myfn(arg As Double) As Double myfn = arg + Rnd() End Function

Cell A1: =myfn(RANDBETWEEN(5,17)) -- this cell-formula proves that myfn(arg) is working: Excel generates a random integer from 5 to 17, and passes it to myfn ; the myfn VBA then adds a random offset

Then I run the following perl, using Win32::OLE :

#!perl use 5.012; # strict, // use warnings; use Win32::OLE; my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); print "output = ", $Excel->Run('myfn', 17), "\n";

The output I get will be some random number from 17 to 18:

output = 17.468005657196

This is using the 'Run' Application Object from the Excel Object Model. The function (or subroutine) name is the first argument to $Excel->Run() ; arguments to that function/subroutine are the remaining arguments.

Replies are listed 'Best First'.
Re^2: Perl vith VBA macros with arguments
by roblesfel (Initiate) on Oct 12, 2022 at 01:44 UTC
    it helped me a lot thanks!!!