Here's the code that I am using:

"""
import comtypes.client

word = comtypes.client.GetActiveObject("Word.Application")
word.Visible = 1
tb = word.CommandBars[1]
btn = tb.Controls[1]
print btn.Caption

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

conn = comtypes.client.ShowEvents(evt)

from comtypes.test.test_showevents import pump_messages
pump_messages(10)
"""

I have installed (but not activated ;-) a copy of word 2003 from someone else.
When running the code I get something similar to you:

C:\svn\theller\comtypes-dist>py25 commandbar_events.py
Neues &leeres Dokument
Traceback (most recent call last):
  File "commandbar_events.py", line 9, in <module>
    evt = word.VBE.Events.CommandBarEvents(btn)
COMError: (-2146822220, None, (u'Dem programmatischen Zugriff auf das Visual 
Basic-Projekt wird nicht vertraut.',
           u'Microsoft Word', u'C:\\Programme\\Microsoft 
Office\\OFFICE11\\1031\\wdmain11.chm', 25548, None))

When I now change the macro security settings in Word to 'Zugriff auf Visual 
Basic Projekte vertrauen'
(allow access for VB projects) then the code runs ok:

C:\svn\theller\comtypes-dist>py25 commandbar_events.py
Neues &leeres Dokument
<POINTER(_CommandBarControlEvents) ptr=0x29d46c at c1c170>
# event found: _dispCommandBarControlEvents_Click

C:\svn\theller\comtypes-dist>

However, the event does not appear, even if I click on the button 'Neues leeres 
Dokument'
(new empty document).  Exactly the same happens when I use Word 97 instead of 
Word 2003.
I have no idea why the event does not fire.

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

Reply via email to