I'm trying to manipulate some fields in a supplied Word 2003 document using the document's own bookmarks using PHP and COM but am getting an error which ever method that I use. If I try to call the Bookmarks directly to substitute the text I get an error: The range cannot be deleted.
function testBkMrkDetails($word, $bookmarkName, $subsTxt) {
try {
$BkMark = $word->ActiveDocument->Bookmarks($bookmarkName);
$range = $BkMark->Range;
if (!$range) {
echo "Range not created ";
}
$range->Text = $subsTxt;
} catch (Exception $e) {
echo "bookmark failed: " . $e->getMessage() . "\n";
}
}
I've searched on Google using the error message and loking for PHP and COM tutorials which appeared to suggest that I look at FormFields so I wrote the following:
function testFormFlds ($word, $bookmarkName, $subsTxt) {
try {
$formField = $word->Selection->FormFields($bookmarkName);
if (!$formField) {
die("Form failed : " . $bookmarkName . " not found\n");
}
$formField->Result($subsTxt);
} catch (Exception $e){
echo "FormField failed: " . $e->getMessage();
}
}
However this keeps telling me that the requested member of the collection does not exists so I'm assuming that I have not called the feild name correctly (it was taen from the document). I would be grateful for some pointers towards solving this and learning more about the underlying technology. Thanks, Iain