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

After I open a Word document, I need to change font size of the existing text from 10 to 9, I tried to do the following, but it doesn't work, please help!
my $Doc = $Word->Documents->Open($mydocument); $Doc->ActiveWindow->Selection->HomeKey(wdStory); $Doc->ActiveWindow->Selection->WholeStory; $Doc->ActiveWindow->Selection->Font->Size('9pt');

Edited by planetscape - added code tags

2006-03-14 Retitled by planetscape, as per Monastery guidelines
Original title: 'Set font size in Words documnet'

Replies are listed 'Best First'.
Re: Set font size in Words document
by marto (Cardinal) on Mar 13, 2006 at 21:34 UTC
Re: Set font size in Words document
by marto (Cardinal) on Mar 14, 2006 at 13:39 UTC
    Hi sungy,

    I am now on a Windows platform and have Microsoft Word available to me.
    If you have not yet found a solution to your problem try the following:
    #!/usr/bin/perl use strict; use warnings; use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; my $file_name = "c:\\temp.doc"; my $Word = Win32::OLE->new('Word.Application'); $Word->{'Visible'} = 1; my $document = $Word->Documents->Open($file_name) || die("Unable to op +en document", Win32::OLE->LastError()); my $Selection = $Word->Selection; $Selection->WholeStory; $Selection->Font->{'Size'} = '9'; $Word->Documents($file_name)->Save(); $Word->Quit();
    Let me know if you have any problems.

    Hope this helps.

    Martin

    Update: Doh!, I should have updated my first post rather than create a second, thats what I get for doing to many things while eating lunch :)
      It works, thanks a lot Martin!