Win32::OLE and Bulleted Lists

J

jr

Hi. I'm trying to bullet a row of text, using Win32::OLE. A module
called "Win32::Word::Writer" seems to do just what I want, but I'm not
able to install it, through either CPAN or PPM. I'm therefore hoping
it is possible to do using only Win32::OLE. I've searched for days,
and the only suggestion I've been able to find is to record a macro in
Word, then port that macro over to Perl. I've tried that, with no luck
(I have zero experience in porting macros). I've also tried recording
a macro, where I bullet a row, and then and looking at the VB code.
This hasn't been helpful either. Is this even possible using only
Win32::OLE? If so, I'd really appreciate an example. This is making
me want to pull out what's left of my hair.

Below is a simple example of the code I found online for creating a
Word document. There must be an easy way, using some method I can't
find anywhere, for bulleting one of the text lines...hopefully, at
least!

Thanks!


####### HelloWord.pl
use warnings;
use strict;

use Win32::OLE;

my $word = CreateObject Win32::OLE 'Word.Application' or die $!;
$word->{'Visible'} = 1;

my $document = $word->Documents->Add;

my $selection = $word->Selection;

$selection ->TypeText("Hello World");
$selection ->TypeParagraph;
$selection ->TypeText("How do you feel today");
$selection ->TypeParagraph;

$selection ->TypeText("Some header");
$selection ->{'Style'} = "Heading 1";

$selection ->TypeParagraph;

my $heading_1 = $document->Styles("Heading 1");
my $heading_1_font = $heading_1 -> Font;

$heading_1_font -> {Name} = "Bookmann";
$heading_1_font -> {Size} = 20;
$heading_1_font -> {Bold} = 1;
 
A

A. Sinan Unur

Hi. I'm trying to bullet a row of text, using Win32::OLE. A module
called "Win32::Word::Writer" seems to do just what I want,

I haven't used that module so I cannot comment on it.
Is this even possible using only Win32::OLE?

Yes. The way to figure this out is to record the simplest possible
macro, then look at it in the VBA editor. The VBA editor has an "Object
Browser" that is accessible via F2. Looking at classes, methods, and
properties in the object browser also helps.

#!/usr/bin/perl

use strict;
use warnings;

use Win32::OLE;
use Win32::OLE::Const 'Microsoft Word';

$Win32::OLE::Warn = 3;

my $word;
eval {
$word = Win32::OLE->GetActiveObject('Word.Application');
};

die "$@\n" if $@;

unless(defined $word) {
$word = Win32::OLE->new('Word.Application', sub { $_[0]->Quit })
or die "Oops, cannot start Word: ", Win32::OLE->LastError, "\n";
}

$word->{Visible} = 1;
my $doc = $word->Documents->Add;

my $selection = $word->Selection;
$selection->Range->ListFormat->ApplyBulletDefault;
$selection->TypeText("Hello World");
$selection->TypeParagraph;
$selection->TypeText("How do you feel today");
$selection->TypeParagraph;


sleep 10;


__END__


Sinan
 
J

jr

A. Sinan Unur said:
Hi. I'm trying to bullet a row of text, using Win32::OLE. A module
called "Win32::Word::Writer" seems to do just what I want,

I haven't used that module so I cannot comment on it.
Is this even possible using only Win32::OLE?

Yes. The way to figure this out is to record the simplest possible
macro, then look at it in the VBA editor. The VBA editor has an "Object
Browser" that is accessible via F2. Looking at classes, methods, and
properties in the object browser also helps.

#!/usr/bin/perl

use strict;
use warnings;

use Win32::OLE;
use Win32::OLE::Const 'Microsoft Word';

$Win32::OLE::Warn = 3;

my $word;
eval {
$word = Win32::OLE->GetActiveObject('Word.Application');
};

die "$@\n" if $@;

unless(defined $word) {
$word = Win32::OLE->new('Word.Application', sub { $_[0]->Quit })
or die "Oops, cannot start Word: ", Win32::OLE->LastError, "\n";
}

$word->{Visible} = 1;
my $doc = $word->Documents->Add;

my $selection = $word->Selection;
$selection->Range->ListFormat->ApplyBulletDefault;
$selection->TypeText("Hello World");
$selection->TypeParagraph;
$selection->TypeText("How do you feel today");
$selection->TypeParagraph;


sleep 10;


__END__


Sinan

Thanks, Sinan. As you suggested, I tried the simplest possible macro
to produce a bulleted list. It revealed the Range, ListFormat,
ApplyBulletDefault methods. Thanks for showing me how to apply these
within Perl. I should now be able to finish my work.

JR
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top