use Win32::OLE; # ... my $excel_source = 'C:\Path\To\Some_workbook.xls'; my $excel = Win32::OLE->CreateObject('Excel.Application'); my $wb = $excel->Workbooks->Add($excel_source); for my $source (in ($wb->{VBProject}->{VBComponents}) ){ print $source->Name, "\n"; my $vb = $source->{CodeModule}; my $linecount = $vb->{CountOfLines}; if( $linecount) { my $body = join "", $vb->Lines(1,$linecount); while ($body =~ /^([^\n]+=\s*"(?:SELECT|INSERT|UPDATE|DELETE) (?:[^\n]*_\r?\n)*[^\n]*?)"\r?\n/imsg) { my $matched= $1; $matched =~ s/^\s*'.*$//mg; # remove all VB comments next unless ($matched =~ /\S/); $matched =~ s/.*?\s*=\s*"//im; $matched =~ s/_\r?\n\s*//g; # rewrap continued lines $matched =~ s/"\s*&\s*"//g; # reconcatenate all strings #print $matched; #print "\n---\n"; if ($matched =~ /(?=from\s+(\w+(\s*,\s*\w+)*))/i) { my $tables = $1; $excel_used{uc $_} = $matched for ($tables =~ /(\w+)/g); } if ($matched =~ /(?=join\s+(\w+)*)/i) { $excel_used{uc $1} = $matched; } push @used_sql, $matched; } }; }