beginner question on using the Win32::OLE module

S

Sylvia

Hello all,

I'm trying to use my first module (and use perl for the first time in a
number of years, too).

I was able to install the Win32::OLE module, but now I'm not sure how
I'd go about doing 2 things:

1. Opening a word doc file on the web
2. Copying all the text from the word doc file into a variable.

This is what I have right now - it doesn't return errors, but it also
doesn't work. I've tried with both local files and word files on the
internet (which is what I need in the end) but neither works.

**************************************************
use strict;
use Win32::OLE ("with");
use Win32::OLE::Variant;
use Win32::OLE::Const 'Microsoft Word';

my $App = Win32::OLE->new('Word.Application') or
die "Cannot create Word.Application";

#my $files = ("c:\junk\test.doc");

# my @files = ("c:\junk\test.doc");
my @files =
("http://www.cityofbellevue.org/departments/Police/files/Press_2005_08_01_2000.doc");


foreach my $file (@files)
{
my $DocText = $App->Selection;
print $DocText;

}

$App->Quit();


**************************************************

Any thoughts as the direction I should be headed in?

thanks much for any advice!

Sylvia
 
S

Sylvia

I got past the error in the code I pasted, but now I'm stuck on another
one. I run this:

******************************************************
use strict;
use Win32::OLE ("with");
use Win32::OLE::Variant;
use Win32::OLE::Const 'Microsoft Word';

my $App = Win32::OLE->new('Word.Application') or
die "Cannot create Word.Application";

my @files =
("http://www.cityofbellevue.org/departments/Police/files/Press_2005_08_01_2000.doc");


my $DocText;
my $MyDoc;

foreach my $file (@files)
{
$MyDoc = $App->Documents->Open($file) ;
$DocText= $MyDoc->Words;

print $DocText;
}
$App->Quit();

******************************************************
My errors are:
1. it comes up with a prompt, that I have to cancel 2 times (when I
access this doc directly from the website,
http://www.cityofbellevue.org/page.asp?view=38806, I don't have this
prompt)
2. The print $DocText doesn't do anything. Am I getting the syntax of
this line wrong?
$DocText= $MyDoc->Words

any help would be much appreciated!!
Sylvia
 
B

Brian Helterline

Sylvia said:
I got past the error in the code I pasted, but now I'm stuck on another
one. I run this:

******************************************************
use strict;
use Win32::OLE ("with");
use Win32::OLE::Variant;
use Win32::OLE::Const 'Microsoft Word';

my $App = Win32::OLE->new('Word.Application') or
die "Cannot create Word.Application";

my @files =
("http://www.cityofbellevue.org/departments/Police/files/Press_2005_08_01_2000.doc");


my $DocText;
my $MyDoc;

foreach my $file (@files)
{
$MyDoc = $App->Documents->Open($file) ;
$DocText= $MyDoc->Words;

This method returns a Words object according to the docs.
If you want to loop over all the words in the document and print them out:

for my $i ( 1 .. $MyDoc->Words->Count )
{
print $MyDoc->Words($i)->Text;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top