[python-win32] Re: Controling MS word from Pytonwin

Thomas Heller theller at python.net
Thu Nov 13 02:57:23 EST 2003


"Shamsul Azhar" <shamsul at handisplay.com.my> writes:

> Hi,
>
> I'm currently writing an application to control MS-Word from Pythonwin. At
> the moment I'm  having problems trying to activate a menu option in word.
> The following code snippets should start Word and activate the "Open" menu
> option.
>
> Using VB the code would look something like :-
>
> Private Sub Command1_Click()
>     Dim wordApp As Word.Application
>     Set wordApp = CreateObject("Word.Application")
>     wordApp.Visible = True
>
>     wordApp.CommandBars.FindControl(ID:=23).Execute
> End Sub
>
> Which when translates to Pythonwin would look like :-
>
> wordApp = win32com.client.Dispatch("word.Application")
> wordApp.visible = 1
> wordApp.CommandBars.FindControl(Id=23).Execute

The last line, when executed in the interactive interpreter, prints
  <bound method CDispatch.Execute of <COMObject FindControl>>
so you only retrieve the method, but do not call it.
Change it to 
> wordApp.CommandBars.FindControl(Id=23).Execute()
and it should work.

Thomas




More information about the Python-win32 mailing list