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

Hi (Monks){

Me again ;-) Does anyone know how to insert a picture into a word document ? I found some code but am getting "Win32::OLE(0.1704) error 0x80020005: "Type mismatch" in METHOD/PROPERTYGET "AddPicture" argument 8 at word.pl line 46" . I can't seem to find any documentation on the Objects and methods. Here is the code:

use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Word'; use Win32::OLE::Const 'Microsoft Office'; # mso constants use Win32::OLE::Variant; my $picture = $document->Shapes->AddPicture ( 'C:\lost-as-usual.bmp', msoFalse, # link to file msoTrue, # save with document 100, 100, 100, 100, $document->ActiveWindow->Selection->{Range} ); $document->SaveAs("$dir\\where-is-my-pic.doc", { 'FileFormat' => wdFormatDocument }); $doc -> Close();

Replies are listed 'Best First'.
Re: MS word insert picture
by vkon (Curate) on Apr 28, 2006 at 19:07 UTC
    first, you don't do
    msoFalse, # link to file msoTrue, # save with document
    Those become string constants.
    So start with use strict; to diagnose those better.

    Better do:

    my $wordconst = Win32::OLE::Const->Load($word); $wordconst->{msoFalse};
    Yet, don't do mixed style OLE calls, like in your 'SaveAs' method, it is not supoprted.