lily123 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks
I have a word document which should be validated and an error report should be generated for that word document. Since perl is a great in text-processing i wanted to use perl to work with word. thinking of using Win32::ole
Now, How can i traslate the methods in VBA into Perl win32 ole methods? Is there extensive reference available?
Or, can u suggest some other better way of acheiving the same?
Thanx
Lal

Replies are listed 'Best First'.
Re: Perl+word
by wfsp (Abbot) on Aug 28, 2004 at 12:14 UTC
    Hi,

    If you search for win32::ole you will find some useful information (for example).

    The code would look like this:

    #!/bin/perl5 use strict; use warnings; use Win32::OLE; my $w = Win32::OLE->GetActiveObject('Word.Application'); my $d = $w->ActiveDocument; my $paras = $d->Paragraphs; foreach my $para ( in $paras ) { my $style = $para->Style->{ NameLocal }; my $text = $para->Range->{ text }; print "$style\t$text\n" }
    This assumes that Word is open with an open document.

    If you're familiar with VBA methods it is fairly easy to work out the perl syntax. The best reference is the VBA help file.

    The win32::ole docs also have some examples.

    Hope this helps, wfsp

Re: Perl+word
by tachyon (Chancellor) on Aug 29, 2004 at 04:03 UTC
      Thanx Guys for ur reply.
      -Lily123
Re: Perl+word
by doowah2004 (Monk) on Aug 31, 2004 at 15:23 UTC
    Check the ole-browser that comes with perl. It should be in /html/Ole-Browser/Browser.html inside your perl directory. It will list all of the VB info, but you will still need to convert to perl. I find that the best way to convert is to look at some examples, then take a wild educated guess, and have lots of patience and a creative mind to work through the different syntax possibilities.

    Cameron