Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing values fromPerl to Word

Status
Not open for further replies.

terryISO

Programmer
Sep 29, 2002
48
0
0
GB
Hi.

Please excuse if this has already been answered somewhere, but of so I can't see it.

I have anumber of programs where I have written a procedure in visual basic, and it operates within Word. As an example, I have a sequence which calls up a word document which contains a VB module called "doFindReplace".:

e.g. (with irrelevant things omitted):

use Win32::OLE::Const;
my $oWord = Win32::OLE->GetActiveObject('Word.Application') || Win32::OLE->new('Word.Application', 'Quit');
my $oDoc = $oWord->Documents->Open("E:/$inputfilename");
$oDoc->{doFindReplace}->{Execute}->{Pause}=1; # Run the Macro in the document
$oWord->{ActiveDocument}->SaveAs("E:/$outputfilename");
$oWord->{ActiveDocument}->Close;
$oDoc->SaveAs("E:/waste.doc");
$oDoc->Close;
unlink("E:/waste.doc");
$oWord->Quit();

***************
My question is, does anyone know how I can pass a value from Perl to the VB module? I imagine it would be something in the line which fires off the module, but I cannot figure it out.

All help greatly appreciated. And thanks even if no-one knows.

I'm running Office 2000 on Win2K and Vista. Vista does seem to affect things somewhat!
 
I have figured out a way around this now and have modified the Perl side of things to instruct the "built-in" Word functions to do what I wanted.


my $filename=$_[0];
my $oWord = Win32::OLE->GetActiveObject('Word.Application', 'Quit') || Win32::OLE->new('Word.Application', 'Quit');

$oWord->{Visible} = 1;

my $clBlue = 16711680;
my $clGreen = 32768;
my $clRed = 255;
my $clBlack = 0;
my $oDoc = $oWord->Documents->Add("c:/AssessmentTemplate.doc");

$oWord->Selection->TypeParagraph;
$oWord->Selection->Font->{Size} = 14;
$oWord->Selection->Font->{Bold} = 9999998;
$oWord->Selection->Font->{Name} = "Arial";
$oWord->Selection->Font->{Color} = 0;
$oWord->Selection->TypeText(" Report\n");
$oWord->Selection->HomeKey({Unit => wdStory});

$oWord->{ActiveDocument}->SaveAs("c:/12.doc");
$oWord->{ActiveDocument}->Close;

Thanks anyway.

But does anyone know how to pass values to a subroutine that I have written and which is included within the Word Document? The above method only seems to work with the built-in functions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top