I got this error while trying to create a word document.
Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft Word<br/><b>Description:</b> The requested member of the collection does not exist.' in C:\xampplite\htdocs\print_short_list.php:25 Stack trace: #0 C:\xampplite\htdocs\print_short_list.php(25): unknown() #1 {main} thrown in C:\xampplite\htdocs\print_short_list.php on line 25
Line 25 is...
$word->Documents[0]->SaveAs($filename);
Here is the entire code
<?php
$word = new COM("word.application");
$word->Visible = 0;
$word->Documents->Add();
$word->Selection->PageSetup->LeftMargin = '2';
$word->Selection->PageSetup->RightMargin = '2';
$word->Selection->Font->Name = 'Arial';
$word->Selection->Font->Size = 10;
$word->Selection->TypeText("TEXT!");
// Save document
$filename = tempnam(sys_get_temp_dir(), "word");
$word->Documents[0]->SaveAs($filename);
$word->quit();
unset($word);
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=document_name.doc");
readfile($filename);
unlink($filename);
?>