Hi
I have a PHP app that formats a Word document, and now the last step is trying to get it to send as an email. The trouble is, that the app will be running on standalone laptops with no internet connection at the time the document is generated, so I need it to be stored in the users email outbox (be it outlook or whatever). I've tried writing a vbscript macro behind the document template, but can't seem to get PHP to call the macro ok....
$word = new COM("word.application") or die("Unable to instanciate Word");
//$word->Visible = 1; doesn't work?
//open an empty document
$template = "c:\\webphp\\documents\\PROPOSAL.dot";
$word->Documents->Add($template);
//do document text.........
$wordFileName = "c:\\webphp\\documents\\Proposal - $customername.doc";
$word->Documents[1]->SaveAs($wordFileName);
$word->Documents[1]->Activate;
$word->Run("TemplateProject.NewMacros.Macro1");
//closing word
$word->Quit();
//free the object
$word->Release();
$word = null;
The Macro, there are basically two versions I've tried, both work when running from Word itself but won't work when called from the $word object
First version:
ThisDocument.HasRoutingSlip = True
With ThisDocument.RoutingSlip
.Subject = "Proposal"
.AddRecipient "Matthew Goudge"
End With
ThisDocument.Route
Second version:
ActiveWindow.EnvelopeVisible = True
WordBasic.EmailSend
This one works in Word because the template has the email address on the envelope saved in it. Obviously I can understand it not working in PHP because I can't actually get Word to be the active window!!!
In both cases, the PHP creates and formats the document OK, and saves it, but when it tries to run the macro it hangs.
If anyone has any ideas why this doesn't work, or has an idea of a better way to do this, help would be very much appreciated!
Matt