Try changing "vbextFileTypeModule" to 1 or find the correct constant, possibly vbext_ct_StdModule.
You'll need to set your macro security settings to low and probably trust access to the project as well.
Update:
This works on Excel 2003 after setting macro security settings to low and trusting access to the project:use strict; use warnings; use Win32::OLE; use Win32::OLE::Const "Microsoft Excel"; use Win32::OLE::Const "Microsoft Visual Basic for Applications Extensi +bility"; my $xls = Win32::OLE->new('Excel.Application'); $xls->{Visible} = -1; my $wb = $xls->Workbooks->Add; my $mod = $wb->VBProject->VBComponents->Add(1); $mod->{Name}="NewMod"; $mod->CodeModule->AddFromString ( <<MODTEXT); Sub Message dim s as string s = "Hello, World" MsgBox s End Sub MODTEXT my $sheet = $xls->Sheets('Sheet1'); my $button = $sheet->Buttons->Add(71.25, 18.75, 88.5, 57); $button->{OnAction} = 'Message';
In reply to Re^3: Creating Excel Macros from Perl
by spivey49
in thread Creating Excel Macros from Perl
by ChumpChief
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |