View Single Post
  #8   Report Post  
Harlan Grove
 
Posts: n/a
Default

newOLE wrote...
so, what's the syntax to run a VBA macro that has arguments

e.g. answer = dothis(a, b, c, d)

Also, does any non-visible function (when I do Alt-F11) loaded through an
add-in become a VBA macro?


Using Evaluate? It needs to look like a cell formula. If you have
Excel, you should have Excel's online help, so you could use that to
check the syntax. If you don't have Excel or its online help, you
shouldn't be trying to automate Excel.

Why don't you just enter the necessary formulas into Excel cells? If
you have an add-in that provides a function named Takes4Arguments which
(oddly enough) takes 4 arguments, you could use something like

# xl_example.2.pl
use Win32::OLE;
$xl = Win32::OLE-CreateObject("Excel.Application");
$wb = $xl-Workbooks-Add;
$ws = $wb-Worksheets(1);
$ws-Cells(1,1)-{'Formula'} = "=Takes4Arguments(1,2,3,4)";
$ws-Cells(2,1)-{'Value'} =
$xl-Evaluate('=Takes4Arguments(1,2,3,4)');
$xl-{'Visible'} = True;
__END__
# leave Excel app instance running