RE: Where am I going wrong with OLE and MS Word?

2003-09-02 Thread Krummel, James C - PGGC-6

Brad,

You where almost there.  Try inserting a section break instead of a page break, then 
select the range following the section break for the margin change.  This is like 
choosing 'From this point forward' in the 'Apply To' combo box in Page Setup.

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

my($outputFile) = "c:\\check_this_file.doc";

my($WordApp) = Win32::OLE -> new('Word.Application', 'Quit');
$WordApp-> {Visible} = 1;
$WordApp -> Documents -> Add;

$PageSetup=$WordApp->ActiveDocument->PageSetup;
$PageSetup -> {LeftMargin}  = $WordApp -> InchesToPoints(0);
$PageSetup -> {RightMargin} = $WordApp -> InchesToPoints(0);
$PageSetup -> {TopMargin}   = $WordApp -> InchesToPoints(0);
$PageSetup -> {BottomMargin}= $WordApp -> InchesToPoints(0);

$coverart="c:/find-out_directory_cover.jpg";
$InsertCover=$WordApp->Selection->InlineShapes->AddPicture({FileName=>$coverart});

# // Start of Mods //
$InsertCover=$WordApp->Selection->InsertBreak({Type=>wdSectionBreakNextPage});
$PageSetup2=$WordApp->ActiveDocument->Range({Start=>$WordApp->Selection->Start, 
End=>$WordApp->ActiveDocument->Content->End})->PageSetup;
# // End of Mods //

$PageSetup2 -> {LeftMargin}  = $WordApp -> InchesToPoints(0.75);
$PageSetup2 -> {RightMargin} = $WordApp -> InchesToPoints(0.75);
$PageSetup2 -> {TopMargin}   = $WordApp -> InchesToPoints(0.75);
$PageSetup2 -> {BottomMargin}= $WordApp -> InchesToPoints(0.75);

$WordApp->Selection->Font->{Size} = '12';
$WordApp->Selection->TypeText( "Let's try some text in here to see what happens." );
$WordApp->ActiveDocument->SaveAs({FileName=>$outputFile, 
FileFormat=>wdFormatDocument});
$WordApp->ActiveDocument->Close();
$WordApp->Quit();


James Krummel

>From: "Brad Smith" <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Date: Tue, 02 Sep 2003 13:54:19 -0400
>Subject: Where am I going wrong with OLE and MS Word?
>
>I have written a little app, where I would like to dynamically create a 
>directory of resource providers, using Perl OLE and Word10.  I would 
>like the directory to contain:
>1.  A full page color graphic
>2.  Table of Contents
>3.  Contents:  each resource provider listed on a page, separated by a 
>page break.
>
>Each of these aspects I have successfully performed, individually.  
>Where I am having my problems is in setting ranges for different 
>formatting.  For instance, the first page, the cover art should bleed to 
>the edges.  Then, a page break, then the Table of Contents, with 1" 
>borders all the way around, page break, followed by the resource 
>provider listings, each separated by a page break and formatted w/ 1" 
>borders.
>
>I begin by using 'PageSetup' to set all margins to 0" (for full bleed).  
>Then, I add the InlineShape to the first page.  Everything works to that 
>point.  Now, I would like to reset the page borders to 1" all around and 
>begin adding the Table of Contents and other text.  Unfortunately, every 
>time I adjust the PageSetup parameters, ALL the margins are reset, 
>negating the 0" margins I had established for the cover art.
>
>I have read every archived email re: OLE and Word, combed my Office 
>Developer's Guide book (VBA), searched Google for anything available, 
>but the examples I have found do not address multiple page margins 
>within a single document.
>
>Below is the code I have written so far.  Is there anyone out there who 
>has fond experiences with OLE automation of Word who can help me 
>through this?  Thanks in advance.
>
>use Win32::OLE;
>use Win32::OLE::Const 'Microsoft Word';
>
>my($outputFile) = "c:/check_this_file.doc";
>
>my($WordApp) = Win32::OLE -> new('Word.Application', 'Quit');
>$WordApp-> {Visible} = 1;
>$WordApp -> Documents -> Add;
>
>$PageSetup=$WordApp->ActiveDocument->PageSetup;
>$PageSetup -> {LeftMargin}  = $WordApp -> InchesToPoints(0);
>$PageSetup -> {RightMargin} = $WordApp -> InchesToPoints(0);
>$PageSetup -> {TopMargin}   = $WordApp -> InchesToPoints(0);
>$PageSetup -> {BottomMargin}= $WordApp -> InchesToPoints(0);
>
>$coverart="c:/find-out_directory_cover.jpg";
>$InsertCover=$WordApp->Selection->InlineShapes-
>>AddPicture({FileName=>$coverart});
>$InsertCover=$WordApp->Selection-
>>InsertBreak({Type=>wdPageBreak});
>
>$PageSetup2=$WordApp->ActiveDocument->PageSetup;
>$PageSetup2 -> {LeftMargin}  = $WordApp -> InchesToPoints(0.75);
>$PageSetup2 -> {RightMargin} = $WordApp -> InchesToPoints(0.75);
>$PageSetup2 -> {TopMargin}   = $WordApp -> InchesToPoints(0.75);
>$PageSetup2 -> {BottomMargin}= $WordApp -> InchesToPoints(0.75);
>
>$WordApp->Selection->Font->{Size} = '12';
>$WordApp->Selection->TypeText( "Let's try some text in here to see 
>what happens." );
>$WordApp->ActiveDocument->SaveAs({FileName=>$outputFile,
>  FileFormat=>wdFormatDocument});
>$WordApp->ActiveDocument->Close();
>$WordApp->Quit();
>
>Brad Smith
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/m

RE: Where am I going wrong with OLE and MS Word?

2003-09-02 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Brad Smith wrote:
> I have written a little app, where I would like to dynamically create
> a directory of resource providers, using Perl OLE and Word10.  I would
> like the directory to contain:
> 1.  A full page color graphic
> 2.  Table of Contents
> 3.  Contents:  each resource provider listed on a page, separated by a
> page break.
> 
> Each of these aspects I have successfully performed, individually.
> Where I am having my problems is in setting ranges for different
> formatting.  For instance, the first page, the cover art should bleed
> to the edges.  Then, a page break, then the Table of Contents, with 1"
> borders all the way around, page break, followed by the resource
> provider listings, each separated by a page break and formatted w/ 1"
> borders.
> 
> I begin by using 'PageSetup' to set all margins to 0" (for full
> bleed). Then, I add the InlineShape to the first page.  Everything
> works to that point.  Now, I would like to reset the page borders to
> 1" all around and begin adding the Table of Contents and other text. 
> Unfortunately, every time I adjust the PageSetup parameters, ALL the
> margins are reset, negating the 0" margins I had established for the
> cover art. 
> 
> I have read every archived email re: OLE and Word, combed my Office
> Developer's Guide book (VBA), searched Google for anything available,
> but the examples I have found do not address multiple page margins
> within a single document.
I do not have Word 10, but in Word 9 when you are on the setup page, there is 
an entire document or from this point forward as regards the margins.  I assume you 
are getting the whole document and what you need after the first Pagesetup is to use 
from thie point forward for any others which follow.

Not much help, but at least a little input.

Wags ;)
> 
> Below is the code I have written so far.  Is there anyone out there
> who has fond experiences with OLE automation of Word who can help me
> through this?  Thanks in advance.
> 
> use Win32::OLE;
> use Win32::OLE::Const 'Microsoft Word';
> 
> my($outputFile) = "c:/check_this_file.doc";
> 
> my($WordApp) = Win32::OLE -> new('Word.Application', 'Quit');
> $WordApp-> {Visible} = 1;
> $WordApp -> Documents -> Add;
> 
> $PageSetup=$WordApp->ActiveDocument->PageSetup;
> $PageSetup -> {LeftMargin}  = $WordApp -> InchesToPoints(0);
> $PageSetup -> {RightMargin} = $WordApp -> InchesToPoints(0);
> $PageSetup -> {TopMargin}   = $WordApp -> InchesToPoints(0);
> $PageSetup -> {BottomMargin}= $WordApp -> InchesToPoints(0);
> 
> $coverart="c:/find-out_directory_cover.jpg";
> $InsertCover=$WordApp->Selection->InlineShapes-
>> AddPicture({FileName=>$coverart});
> $InsertCover=$WordApp->Selection-
>> InsertBreak({Type=>wdPageBreak});
> 
> $PageSetup2=$WordApp->ActiveDocument->PageSetup;
> $PageSetup2 -> {LeftMargin}  = $WordApp -> InchesToPoints(0.75);
> $PageSetup2 -> {RightMargin} = $WordApp -> InchesToPoints(0.75);
> $PageSetup2 -> {TopMargin}   = $WordApp -> InchesToPoints(0.75);
> $PageSetup2 -> {BottomMargin}= $WordApp -> InchesToPoints(0.75);
> 
> $WordApp->Selection->Font->{Size} = '12';
> $WordApp->Selection->TypeText( "Let's try some text in here to see
> what happens." );
> $WordApp->ActiveDocument->SaveAs({FileName=>$outputFile,
>   FileFormat=>wdFormatDocument});
> $WordApp->ActiveDocument->Close();
> $WordApp->Quit();
> 
> Brad Smith
> 
> ___
> Perl-Win32-Users mailing list
> [EMAIL PROTECTED]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



**
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.



___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs