|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-12-22 07:34 UTC] poon dot fung at gmail dot com
Description:
------------
I can call a Word macro without any argument ok. But when I pass a string arguement to a Word macro, I get the following exception.
Source: Unknown
Description: Unknown
I discovered the following problem:
1. It works when a macro does not have argument. The macro can be in the default macro file "Module/NewMacros" or other module file such as "Module/MyMacros".
2. It works when a macro has one or more arguements when the macro is in default macro file "Module/NewMacros".
It does not work when the same macro is copied to a different module file such as "Module/MyMacros".
Reproduce code:
---------------
<?php
// C:\testme.doc is any Word document
$word = new COM('Word.Application') or die('Start Word automation failed.');
$word->Documents->Open('c:\testme.doc');
$arg1 = 'Some value';
// First test --> This works fine
//$word->Application->Run('phptest1');
// Second test --> This works fine
//$word->Application->Run('phptest2', $arg1);
// Third test --> This works fine
//$word->Application->Run('phptest3', $arg1, $arg1);
// Forth test --> This works fine
//$word->Application->Run('Normal.MyMacros.phptest1');
// Fifth test --> FAILED
$word->Application->Run('Normal.MyMacros.phptest2', $arg1);
// Sixth test --> FAILED
//$word->Application->Run('Normal.MyMacros.phptest3', $arg1, $arg1);
$word->Quit();
$word = null;
/*
// Word macros
Sub phptest1()
End Sub
Sub phptest2(arg1 As String)
End Sub
Sub phptest3(arg1 As String, arg2 As String)
End Sub
*/
?>
Expected result:
----------------
To run the test:
1. Create a dummy Word document C:\testme.doc".
2. Copy the three dummy procedures (phptest1, phptest2 and phptest3) to Word's macro file "Normal/Module/NewMacros".
3. Create a new macro file "Normal/Module/MyMacros" and paste the same three procedures in it.
4. Uncomment the line after each test case and keep lines for other test cases commented.
5. Run each test case.
Case 1-4: No output. Just finish without error.
Case 5-6: Show the error below.
Actual result:
--------------
PHP Fatal error: Uncaught exception 'com_exception' with message 'Source: Unknown
Description: Unknown' in C:\bug2.php:21
Stack trace:
#0 C:\bug2.php(21): variant->Run('Normal.MyMacros...', 'Some value')
#1 {main}
thrown in C:\bug2.php on line 21
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 21:00:01 2025 UTC |
I have recreated the problem reported by this bug report using the instructions provided and get exactly the error reported. However, after investigating of the problem I am now of the opinion that the defect lies in Word and not in PHP or the COM extension. First of all the problem appears to have nothing to do with whether the macro is in the default macro file or not. The error has more to do with how the "macroname" parameter itself is specified. For a macro defined in the default macro file which has no arguments then any of the following work without problems: $word->Application->Run("phptest1"); $word->Application->Run("NewMacros.phptest1"); $word->Application->Run("Normal.NewMacros.phptest1"); However, for a macro with one argument then either of the following are OK: $word->Application->Run("phptest2","string1"); $word->Application->Run("NewMacros.phptest2", "string1"); but when the full name for the macro is specified as follows $word->Application->Run("Normal.NewMacros.phptest2", "string1"); then the reported exception is thrown: btw the "scode" in the returned EXCEPINFO structure is 0x"80020003" , i.e specified macro not found, but bstrSource and bstrDescription are both NULL hence the rather unhelpful exception message produced by COM extension, i.e Fatal error: Uncaught exception 'com_exception' with message 'Source: Unknown Description: Unknown' in C:\Eclipse-PHP\workspace\Testcases\COM\d39930.php:30 If I define the same macros in another macro file, e.g "AndyMacros", then I get the same results, So it looks like an issue when the template name is specified in the "macroname" parametr when the macro takes 1 or more arguments, i.e a macro name of the form "<template>.<module>.<macro>" is specified WITH arguments. To further show this is not a PHP or COM issue I rewrote the testcase using VB as follows: http://www.pastebin.ca/324546 When I run this script with either of lines 18 or 19 not commented out, i.e word.Application.Run "Normal.NewMacros.phptest2", "string1" or word.Application.Run "Normal.NewMacros.phptest3", "string1", "string2" then the script fails with "C:\VBscripts\d39930.vbs(18, 1) Microsoft VBScript runtime error: Object doesn't support this property or method." As with PHP errors are only reported when the "template" is specified in the "macroname". This suggests to me that the reported problem does indeed lie in Word and not PHP. Searching the web I did find this very old bug report for Word 97 from 2000 which looks like a similar issue: http://support.microsoft.com/kb/190235. This suggests the "template" name be removed from the macroname argument as a workaround which ties in with my findings above.