Solved

Word and COM

Posted on 2004-08-18
3
358 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
  • 2
3 Comments
 

Author Comment

by:drakkarnoir
Comment Utility
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
Comment Utility
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
Comment Utility
Going to do this with .NET, thanks guys.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now