Trying to manipulate MS Word bookmarks using PHP and COM
I'm trying to manipulate some of the fields in a supplied Word 2003 document using native document bookmarks using PHP and COM, but I get an error that I have ever used the method. If I try to invoke the bookmarks directly to replace the text, I get the 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 have searched Google using the error message and running for PHP and COM tutorials that seem to suggest that I am looking at FormFields, so I wrote this:
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 suggests that the requested collection member does not exist, so I am assuming that I did not call the feild name correctly (it was from the doc). I would appreciate some guidance on how to address this and learn more about the underlying technology. Thanks, Iain
source to share
No one has answered this question yet
Check out similar questions: