Your code doesn't run because - at least - only you have your directories and files. It's therefore impossible to reproduce your problem. The best I can do is to write some code that does work but reproduces my best guess at your situation. If you can give us working code that demonstrates your problem, I might be able to do better.
use strict; use warnings; use Win32::OLE; my $xl = Win32::OLE->new('Excel.Application'); $xl->{Visible} = 1; my $wb = $xl->Workbooks->Add; if ($wb->Sheets->{Count} > 1) { for (2..$wb->Sheets->{Count}) { $wb->Sheets(2)->Delete; } } $xl->VBE->ActiveVBProject->VBComponents->Add(1); my $cm = $xl->VBE->ActiveVBProject->VBComponents(3)->CodeModule; my $line = int($cm->CountOfLines); $cm->InsertLines(++$line,"Function Example(n as double) as double"); $cm->InsertLines(++$line,"Example = n^2"); $cm->InsertLines(++$line,"End Function"); my $sht = $wb->Sheets(1); $sht->Range("A1")->{Formula} = "=Example(2)"; $sht->Range("A2")->{Formula} = "=2*2"; my $a1 = $sht->Range("A1")->{Value}; my $a2 = $sht->Range("A2")->{Value}; if ($a1 != 4 or $a2 != 4) {print "We've had a problem"} else {print "L +ife is good"};
Regards,
John Davies
In reply to Re: Excel OLE cell value custome pre-defined predefined function formula error
by davies
in thread Excel OLE cell value custome pre-defined predefined function formula error
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |