I am trying to populate an excel workbook and I want to use an existing sheet if it is there and if not create a sheet. Without cycling through all sheet names in a for loop, I am not sure how to do this. The code I have tried is...
unless (defined $UseSheet)
{
$Sheet = $Book->Worksheets()->Add();
$Sheet->{Name} = "$UseSheet";
}
else
{
$Sheet = $Book->Worksheets( $UseSheet );
}
$ec=Win32::OLE->LastError();
print "$ec\n";
The error returned is ...
Win32::OLE(0.1601) error 0x8002000b: "Invalid index"
in METHOD/PROPERTYGET "Worksheets"
unless (defined $UseSheet)
{
$Sheet = $Book->Worksheets()->Add();
$Sheet->{Name} = "$UseSheet";
}
else
{
$Sheet = $Book->Worksheets( $UseSheet );
}
$ec=Win32::OLE->LastError();
print "$ec\n";
The error returned is ...
Win32::OLE(0.1601) error 0x8002000b: "Invalid index"
in METHOD/PROPERTYGET "Worksheets"