I'm working on a program the plays with PowerPoint and Word, transferring info between the two. The PPT side works fine. I'm on W2k with ActiveState 6.5.1 build 629. Office 2000.

I'm trying to write stuff in two fonts in Word. I've searched SuperSearch and google and this is the best I've come up with:

use Diagnostics; use strict; use Win32::GUI; use Win32; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Word'; use Win32::OLE::Const 'Microsoft PowerPoint'; my $wordApp = Win32::OLE->GetActiveObject('Word.Application') || Win32::OLE->new('Word.Application', sub {$_[0]->Quit;}) or die "NO WORD!" ; $wordApp->{Visible} = 1; my $wordDoc = $wordApp->Documents->Add("/work/CG.dot"); # Go to the insertion point my $point = $wordDoc->GoTo({What => wdGoToBookmark, Name => "Start"}); my $ins_range = $point->Duplicate; #insert in default font $ins_range->InsertAfter("Hello"); $ins_range->InsertParagraphAfter(); # $ins_range->Font->Name = "Arial" gives illegal lvalue $ins_range->Font->Name("Courier New"); $ins_range->InsertAfter("GoodBye"); #Also, this fails with type mismatch in my real proggie # but not when I take it as an example; my $dst = "foo.doc"; $wordApp->ActiveDocument->SaveAs({ FileName => $dst, FileFormat => wdFormatDocument });
Unfortunately the font never changes in the document. The text is inserted correctly otherwise. I have tried (as you can see from the comments) a few things. Also, strangely, in my real program the "saveas" dies with a type mismatch, but here it does not. Any help would be appreciated. Oh, BTW, I know that saveas prompts. That is for debugging.

Thanks! --traveler


In reply to MSWord OLE, font and saveas Problems by traveler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.