add macro to sheet instead to module

S

shahrahulb

my $excel =
Win32::OLE->GetActiveObject('Excel.Application')
||
Win32::OLE->new('Excel.Application', 'Quit');

my $Book = $excel->Workbooks->Open("C:\\test.xls") || die "Error";

my $comp = $Book->VBProject->VBComponents->Add(1);
$comp->{Name} = 'my_macros';

# Add our subroutine to the module.
my $module = $comp->Codemodule;
$module->AddFromString($code);

Problem i sthis adds the macro ($code) to the module
Is there a way to add the macro to Sheet1 (because my exception
sub-routine works only from sheet1 and not from module)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,183
Messages
2,570,969
Members
47,524
Latest member
ecomwebdesign

Latest Threads

Top