I'm trying to extract data from multiple Tables in a Word document. When trying to convert the data in the tables to text I get an error. The ConvertToText method has two optional parameters(how to seperate the data, and a boolean).Here is my current code:
#usr/bin/perl
#OLEWord.pl
#Use string and print warnings
use strict;use warnings;
#Using OLE + OLE constants for Variants and OLE enumeration for Enumerations
use Win32::OLE qw(in);
use Win32::OLE::Const 'Microsoft Word';
use Win32::OLE::Variant;
my $var1 = Win32::OLE::Variant->new(VT_BOOL, 'true');
$Win32::OLE::Warn = 3;
#set the file to be opened
my $file = 'C:\work\SCL_International Financial New Fund Setup Questionnaire V1.6.docx';
#Create a new instance of Win32::OLE for the Word application, die if could not open the application
my $MSWord = Win32::OLE->GetActiveObject('Excel.Application') or Win32::OLE->new('Word.Application','Quit');
#Set the screen to Visible, so that you can see what is going on
$MSWord->{'Visible'} = 1;
$MSWord->{'DisplayAlerts'} = 0; #Supress Alerts, such as 'Save As....'
#open the request file or die and print warning message
my $Doc = $MSWord->{'Documents'}->Open($file) or die "Could not open ", $file, " Error:", Win32::OLE->LastError();
#$MSWord->ActiveDocument->SaveAs({Filename => 'AlteredTest.docx',
#FileFormat => wdFormatDocument});
my $tables = $MSWord->ActiveDocument->{'Tables'};
for my $table (in $tables){
my $tableText = $table->ConverToText(wdSeparateByParagraphs,$var1);
print "Table: ", $tableText, "\n";
}
$MSWord->ActiveDocument->Close;
$MSWord->Quit;
and I'm getting this error:
Bareword "VT_BOOL" not allowed while "strict subs" in use at OLEWord.pl line 31
Bareword "true" not allowed while "strict subs" in use at OLEWord.pl line 31
Execution of OLEWord.pl aborted due to compilation errors.