in reply to create .docx files (MS-WORD with WIN32::OLE)

You need to Add a document ;
use strict; use warnings; use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; my $My_Word = Win32::OLE->new('Word.Application') or die "Problem with MS-WORD"; my $counter = 4534; my $path = 'C:/temp/'; while(<DATA>) { chomp $_; $counter++; my $docx_name = $path.$counter.".docx"; $My_Word->Documents->Add || die("Unable to create document ", Win32: +:OLE->LastError()); $My_Word->{'Visible'} = 0; $My_Word->{DisplayAlerts} = 0; $My_Word->Selection->TypeText ({ Text => $_ }); $My_Word->ActiveDocument->SaveAs( $docx_name ); $My_Word->{ActiveDocument}->Close; print "Created $docx_name\n"; } $My_Word->Quit; __DATA__ First Document Second Document Third Document
poj

Replies are listed 'Best First'.
Re^2: create .docx files (MS-WORD with WIN32::OLE)
by Corion (Patriarch) on May 04, 2013 at 13:45 UTC

    $My_Word->Documents->Add returns the document. In my experience it's much better to work with that returned document directly instead of resorting to ->ActiveDocument.