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

Hi Monks,

I wanna add a template using Win32::OLE. The below approach yields correct output in VBA, but not in perl.

$word=Win32::OLE->GetActiveObject('Word.Application'); $doc->Open("$file"); $add=$word->AddIns; $a=$add->Add({FileName=>"d:/macro.dot", Install=>"True"});
Last line of code not funcitoning well. Can anyone suggest where i am going wrong?

Thanx in Advance

--c

20050207 Janitored by Corion: Eliminated PRE tags

2005-02-07 Janitored by Arunbear: Changed title from 'Win 32'

Replies are listed 'Best First'.
Re: adding MS-Word templates using Win32::OLE
by gube (Parson) on Feb 07, 2005 at 12:07 UTC

    Hi, Easy try this

    use Win32; use Win32::OLE; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Word'; use Constant 'True' => 1; use Constant 'False' => 0; $word=Win32::OLE->GetActiveObject('Word.Application'); $word->AddIns->Add ({FileName=>"D:\\sample.dot", Install=>"True"});

    Regards,
    Gubendran.L
      Still, I am not getting it correctly.

        Hi, cogniziant while running this code please open the word and create first the template file and also be sure u having the ole module with u else contact me the further details through my inbox. Do it in above instruction given correct code. Download the module in CPAN and try. The above mentioned first given answer is exactly correct. I have tried and then only i posted it.

        Gubendran

Re: adding MS-Word templates using Win32::OLE
by holli (Abbot) on Feb 07, 2005 at 16:46 UTC
    $word=Win32::OLE->GetActiveObject('Word.Application');
    tries to get an existing instance of a Word-object (in other words, a running word). This is of course successful when the code runs as a word-makro. In a standalone-script you will have to create a new instance:
    $word=Win32::OLE->CreateObject('Word.Application');
    holli, /regexed monk/