Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Perl vith VBA macros with arguments

by pryrt (Abbot)
on Oct 11, 2022 at 20:59 UTC ( #11147359=note: print w/replies, xml ) Need Help??

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!!!

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11147359]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2023-03-22 20:12 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (60 votes). Check out past polls.