#39930 [Com]: Error passing Word macro arguments

2007-01-22 Thread wharmby at uk dot ibm dot com
 ID:   39930
 Comment by:   wharmby at uk dot ibm dot com
 Reported By:  poon dot fung at gmail dot com
 Status:   Open
 Bug Type: COM related
 Operating System: Windows XP
 PHP Version:  5.2.0
 New Comment:

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 0x80020003 ,
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.


Previous Comments:


[2007-01-19 09:23:00] wharmby at uk dot ibm dot com

As promised on internals list back in December I will attempt to
resolve some of the outstanding COM defects. 

I will start with this one.



[2007-01-04 07:43:19] poon dot fung at gmail dot com

Here is the output of my test run on
http://snaps.php.net/win32/php5.2-win32-latest.zip.

--- START OUTPUT ---
D:\php-bug2bug2-test1.php
TEST #1 OK!

D:\php-bug2bug2-test2.php
TEST #2 OK!

D:\php-bug2bug2-test3.php
TEST #3 OK!

D:\php-bug2bug2-test4.php
TEST #4 OK!

D:\php-bug2bug2-test5.php
PHP Fatal error:  Uncaught exception 'com_exception' with message
'Source: Unknown
Description: Unknown' in D:\php-bug2\bug2-test5.php:9
Stack trace:
#0 D:\php-bug2\bug2-test5.php(9): variant-Run('Normal.MyModule...',
'Some value')
#1 {main}
  thrown in D:\php-bug2\bug2-test5.php on line 9

D:\php-bug2bug2-test6.php
PHP Fatal error:  Uncaught exception 'com_exception' with message
'Source: Unknown
Description: Unknown' in D:\php-bug2\bug2-test6.php:9
Stack trace:
#0 D:\php-bug2\bug2-test6.php(9): variant-Run('Normal.MyModule...',
'Some value', 'Some value')
#1 {main}
  thrown in D:\php-bug2\bug2-test6.php on line 9

D:\php-bug2
--- END OUTPUT ---

Here are the test programs.

--- TEST 1 ---
?php
// First test -- This works fine

$word = new COM('Word.Application') or die('Start Word automation
failed.');
$word-Documents-Open('D:\php-bug2\testme.doc');

$word-Application-Run('phptest1');

$word-Quit();
$word = null;

print TEST #1 OK!\n;

?

--- TEST 2 ---

?php

// Second test -- This works fine

$word = new COM('Word.Application') or die('Start Word automation
failed.');
$word-Documents-Open('D:\php-bug2\testme.doc');

$arg1 = 'Some value';
$word-Application-Run('phptest2', $arg1);

$word-Quit();
$word = null;

print TEST #2 OK!\n;

?

--- TEST 

#39930 [Com]: Error passing Word macro arguments

2007-01-19 Thread wharmby at uk dot ibm dot com
 ID:   39930
 Comment by:   wharmby at uk dot ibm dot com
 Reported By:  poon dot fung at gmail dot com
 Status:   Open
 Bug Type: COM related
 Operating System: Windows XP
 PHP Version:  5.2.0
 New Comment:

As promised on internals list back in December I will attempt to
resolve some of the outstanding COM defects. 

I will start with this one.


Previous Comments:


[2007-01-04 07:43:19] poon dot fung at gmail dot com

Here is the output of my test run on
http://snaps.php.net/win32/php5.2-win32-latest.zip.

--- START OUTPUT ---
D:\php-bug2bug2-test1.php
TEST #1 OK!

D:\php-bug2bug2-test2.php
TEST #2 OK!

D:\php-bug2bug2-test3.php
TEST #3 OK!

D:\php-bug2bug2-test4.php
TEST #4 OK!

D:\php-bug2bug2-test5.php
PHP Fatal error:  Uncaught exception 'com_exception' with message
'Source: Unknown
Description: Unknown' in D:\php-bug2\bug2-test5.php:9
Stack trace:
#0 D:\php-bug2\bug2-test5.php(9): variant-Run('Normal.MyModule...',
'Some value')
#1 {main}
  thrown in D:\php-bug2\bug2-test5.php on line 9

D:\php-bug2bug2-test6.php
PHP Fatal error:  Uncaught exception 'com_exception' with message
'Source: Unknown
Description: Unknown' in D:\php-bug2\bug2-test6.php:9
Stack trace:
#0 D:\php-bug2\bug2-test6.php(9): variant-Run('Normal.MyModule...',
'Some value', 'Some value')
#1 {main}
  thrown in D:\php-bug2\bug2-test6.php on line 9

D:\php-bug2
--- END OUTPUT ---

Here are the test programs.

--- TEST 1 ---
?php
// First test -- This works fine

$word = new COM('Word.Application') or die('Start Word automation
failed.');
$word-Documents-Open('D:\php-bug2\testme.doc');

$word-Application-Run('phptest1');

$word-Quit();
$word = null;

print TEST #1 OK!\n;

?

--- TEST 2 ---

?php

// Second test -- This works fine

$word = new COM('Word.Application') or die('Start Word automation
failed.');
$word-Documents-Open('D:\php-bug2\testme.doc');

$arg1 = 'Some value';
$word-Application-Run('phptest2', $arg1);

$word-Quit();
$word = null;

print TEST #2 OK!\n;

?

--- TEST 3 ---

?php

// Third test -- This works fine

$word = new COM('Word.Application') or die('Start Word automation
failed.');
$word-Documents-Open('D:\php-bug2\testme.doc');

$arg1 = 'Some value';
$word-Application-Run('phptest3', $arg1, $arg1);

$word-Quit();
$word = null;

print TEST #3 OK!\n;

?

--- TEST 4 ---

?php

// Forth test -- This works fine

$word = new COM('Word.Application') or die('Start Word automation
failed.');
$word-Documents-Open('D:\php-bug2\testme.doc');

$arg1 = 'Some value';
$word-Application-Run('Normal.MyModule.phptest1');

$word-Quit();
$word = null;

print TEST #4 OK!\n;

?

--- TEST 5 ---

?php

// Fifth test -- FAILED

$word = new COM('Word.Application') or die('Start Word automation
failed.');
$word-Documents-Open('D:\php-bug2\testme.doc');

$arg1 = 'Some value';
$word-Application-Run('Normal.MyModule.phptest2', $arg1);

$word-Quit();
$word = null;

print TEST #5 OK!\n;

?

--- TEST 6 ---

?php

// Sixth test -- FAILED

$word = new COM('Word.Application') or die('Start Word automation
failed.');
$word-Documents-Open('D:\php-bug2\testme.doc');

$arg1 = 'Some value';
$word-Application-Run('Normal.MyModule.phptest3', $arg1, $arg1);

$word-Quit();
$word = null;

print TEST #6 OK!\n;

?



[2007-01-02 01:00:00] php-bugs at lists dot php dot net

No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to Open.



[2006-12-25 02:55:29] [EMAIL PROTECTED]

Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip





[2006-12-22 07:34:47] 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 --