#!/usr/bin/perl -w use strict; use warnings; use Cwd; use Win32::OLE; use Win32::OLE qw(in with); use Win32::OLE::Variant; use Win32::OLE::Const 'Microsoft Excel'; use constant TRUE => 1; use constant FALSE => 0; my $fname = shift @ARGV; my $numlines; my $sheetname; my $vb_obj; my $wb_obj; my $xl_obj; $xl_obj = Win32::OLE->new('Excel.Application'); $wb_obj = $xl_obj->Workbooks->Add($fname); for my $source ( in($wb_obj->{VBProject}->{VBComponents}) ) { $sheetname = $source->Name; $vb_obj = $source->{CodeModule}; $numlines = $vb_obj->{CountOfLines}; if ( $numlines ) { my @LINES = $vb_obj->Lines(1, $numlines); print '='x78, "\n"; print "$sheetname\.bas ($numlines lines)\n"; print '='x78, "\n"; my @LINES2 = split /\n/, $LINES[0]; foreach ( @LINES2 ) { s/\x0D//g; chomp; print "$_\n"; } print "\n"; } # end if $numlines undef $vb_obj; } # next my $source undef $wb_obj; undef $xl_obj;