Solved

Word and COM

Posted on 2004-08-18
3
387 Views
Last Modified: 2008-02-01
Reference:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_wrcore/html/wrtskhowtoreplacetext.asp

Ok so I tried to mimick the code C# in PHP, came up with the following code:

<?php

$word = new COM("Word.Application") or die("Unable to create Word");

$word->Visible = TRUE;

$empty = new VARIANT();

$word->Application->ChangeFileOpenDirectory("C:\\");
$word->Documents->Open("test.doc");

$word->Selection->Find->ClearFormatting();
$word->Selection->Find->Text = "Php";

$word->Selection->Find->Replacement->ClearFormatting();
$word->Selection->Find->Replacement->Text = "Hi";

$word->Selection->Find->Execute(&$empty,
&$empty,&$empty,&$empty,
&$empty,&$empty,&$empty,
&$empty,&$empty,&$empty,
$word->WdReplace->wdReplaceAll,&$empty,&$empty,
&$empty,&$empty);



$word->Quit($empty,$empty,$empty);

?>

And it does not seem to work. It just times out, can somebody see what I might be missing?
0
Comment
Question by:drakkarnoir
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:drakkarnoir
ID: 11833456
Fatal error: Uncaught exception 'com_exception' with message 'Unable to lookup `WdReplace': Unknown name. ' in C:\word.php:25 Stack trace: #0 {main} thrown in C:\word.php on line 25
0
 
LVL 7

Accepted Solution

by:
petoskey-001 earned 500 total points
ID: 11838106
I've seen this before.  Try the code from this previous answer and see if it works for you.
http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_20306226.html
0
 

Author Comment

by:drakkarnoir
ID: 11848761
Going to do this with .NET, thanks guys.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question