?
Solved

Word and COM

Posted on 2004-08-18
3
Medium Priority
?
395 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 2000 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

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

800 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