I've looked on Microsoft's web site  and there's a knowledge base for this 
error saying that I have to enable access to Visual Basic Project, but when I 
tried to do that I saw that access was already grated for VB, but I was still 
getting this error message. I've changed the Macro security level to: "Low(not 
recomended)" and now I get another error message:

"Traceback (most recent call last):
  File "D:\Test\test.py", line 104, in test2
    evt = word.VBE.Events.CommandBarEvents(btn)
  File "c:\Python24\Lib\site-packages\comtypes\__init__.py", line 601, in __call
__
    return self.getter(self.im_inst, *args)
COMError: (-2146827864, None, (None, None, None, 0, None))"

I didn't find a solution for this error, also I can't say that setting the 
mocro security level to low is a good solution for the other error as well.
If anyone has any ideas I'll be willing to try.

Thanks  a million,
Radu.

----- Original Message ----
From: Radu Adrian Ciora <[EMAIL PROTECTED]>
To: comtypes-users@lists.sourceforge.net
Sent: Monday, November 5, 2007 11:06:23 AM
Subject: Re: [comtypes-users] View Word's toolbar events


Hi,

I've taken the 0.4.0 release and I put your code in the test but I get the 
error:

"Traceback (most recent call last):
  File "D:\Test\test.py", line 104, in test2
    evt = word.VBE.Events.CommandBarEvents(btn)
COMError: (-2146822220, None, (u'Programmatic access to Visual Basic Project is
not trusted.', u'Microsoft Word', u'C:\\Program Files\\Microsoft Office\\OFFICE1
1\\1033\\wdmain11.chm', 25548, None))"

P.S. I have Ms word 2003.
If you have suggestions I'll be willing to try.

Thanks a million,
Radu.

----- Original Message ----
From: Thomas Heller
 <[EMAIL PROTECTED]>
To: comtypes-users@lists.sourceforge.net
Sent: Friday, November 2, 2007 7:48:05 PM
Subject: Re: [comtypes-users] View Word's toolbar events


Radu Adrian Ciora schrieb:
> Hi,
> 
> I have modified the test_showevents.py with the following code:
> def test(self):
>         o = comtypes.client.GetActiveObject("Word.Application")
>         o.Visible = 1
>         toolbar = o.CommandBars("Standard")
>         print toolbar
>        
 comtypes.client.GetModule(os.path.join(os.environ["CommonProgramFiles"], 
r"Microsoft Shared\OFFICE11\MSO.dll"))
>         from comtypes.gen import Office
>         print Office.CommandBars, Office.CommandBarControl   
>         while 1:
>             conn = comtypes.client.ShowEvents(toolbar)

> 
> but I get the following error :
> 
> Traceback (most recent call last):
[...]
> TypeError: cannot determine source interface
> 
> Is it possible to get events generated by the toolbar?

On the internet I found code that shows how to do it, in VB.
  Apparently
the CommandBar controls have their own way in which they expose events,
 you 
have to pass them to the 'word.VBE.Events.CommandBarEvents()' function,
 and that
will deliver the events then:

        word = comtypes.client.CreateObject("Word.Application")
        word.Visible = 1
        tb = word.CommandBars("Standard")
        btn = tb.Controls[1]

        evt = word.VBE.Events.CommandBarEvents(btn)

        from comtypes.gen import VBIDE

        comtypes.client.ShowEvents(evt,
 interface=VBIDE._dispCommandBarControlEvents)


Unfortunately you have to supply the event interface in the ShowEvents
 call,
because comtypes currently is not able to find out this interface
 itself.
I have already fixed this bug in SVN, so in the next version (or if you
grab the svn version) you should be able to use:

        comtypes.client.ShowEvents(evt)

Please note that the comtypes.gen.VBIDE module is automatically
 generated;
there is no need to call GetModule() in your code (at least that was
 the case for me,
but I only have Word97 installed).

Thomas


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users





__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 




__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users

Reply via email to