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

Re: Perl vith VBA macros with arguments

by pryrt (Abbot)
on Oct 11, 2022 at 20:59 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-19 00:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found