I am trying to write to a Word document using this code:-

<?php
// starting word
$word = new COM("word.application") or die("Unable to instantiate Word");
echo "Loaded Word, version {$word->Version}\n";

//bring it to front
$word->Visible = 1;

//open an empty document
$word->Documents->Add();

//do some weird stuff
$word->Selection->TypeText("This is a test...");
$word->ActiveDocument->SaveAs("c:\Useless test.doc");

//closing word
$word->Quit();

//free the object
$word = null;
?>

When running this code i get this error 'Call to undefined method variant::SaveAs() '

I have tried altering the permissons for the COM setting but it has not work.
I am using PHP locally and I am logging in as a differnet user than the one I installed Word on.

I am using xampp with Windows Vista.

Please help.

Simon.

    the manual example has:

    $word->Documents[1]->SaveAs("Useless test.doc");

    where as you have:

    $word->ActiveDocument->SaveAs("c:\Useless test.doc");

      While you might try using the Documents property, the ActiveDocument member should return the same Document object, so I'm not sure why you'd be getting that error message.

        well yeah i was just guessing :-) if new COM works how can anything there be undefined?

          Thinking outside the box ... Windows Vista, UAC, permissions issue?

          EDIT: Of course, you'd expect a meaningful error message from PHP....

            Write a Reply...