traveler has asked for the wisdom of the Perl Monks concerning the following question:
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:
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.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 });
Thanks! --traveler
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: MSWord OLE, font and saveas Problems
by c-era (Curate) on Nov 09, 2001 at 01:01 UTC | |
by traveler (Parson) on Nov 09, 2001 at 01:29 UTC | |
|
Re: MSWord OLE, font and saveas Problems
by Anonymous Monk on Dec 22, 2004 at 18:50 UTC |