Send a save command to MS-Word in iewin.IEHtmlWindow ?

hello,

I use iewin.IEHtmlWindow to embed MS-word editing in my application.

The word document is generated from a template and already stored on
disk,

so it has a filename already.

If I edit the word document in iewin.IEHtmlWindow,

I want it to be saved automatically (e.g. if I push a close buttton or
navigate to another page).

If I give a ctrl-S, before moving to another page,

this works perfectly, without any word-dialogs.

But if I don’t give the ctrl-S, I get an ugly word dialog, asking me if
I want to save the changes.

I tried send-keys, but that doesn’t work :

` def _On_IE_Close ( self, event ) :

self.Html.SetFocus ()                 # set focus to the

iewin.IEHtmlWindow

wx.CallLater ( 500, self.Aap )

def Aap ( self ) :

import SendKeys

SendKeys.SendKeys ( '^s' )

wx.Sleep ( 1 )

self._IE_Doc_Close ()                 # close the doc, by moving to

another dummy URL

`

Any suggestions / solutions ?

thanks,

Stef Mientki

IIRC when IE loads an ActiveX control like this then the IE window's Document property will expose the API of the activeX object (Word in this case). So if Word exposes some API function like SaveFile (I have no idea if it does or not) then you should be able to get to it like this:

  self.Html.Document.SaveFile()

Hope that helps.

···

On 3/29/10 2:28 AM, Stef Mientki wrote:

hello,

I use iewin.IEHtmlWindow to embed MS-word editing in my application.
The word document is generated from a template and already stored on disk,
so it has a filename already.

If I edit the word document in iewin.IEHtmlWindow,
I want it to be saved automatically (e.g. if I push a close buttton or
navigate to another page).

If I give a ctrl-S, before moving to another page,
this works perfectly, without any word-dialogs.

But if I don't give the ctrl-S, I get an ugly word dialog, asking me if
I want to save the changes.

I tried send-keys, but that doesn't work :
def _On_IE_Close ( self, event ) :
self.Html.SetFocus () # set focus to the iewin.IEHtmlWindow
wx.CallLater ( 500, self.Aap )
def Aap ( self ) :
import SendKeys
SendKeys.SendKeys ( '^s' )
wx.Sleep ( 1 )
self._IE_Doc_Close () # close the doc, by moving to another dummy URL

Any suggestions / solutions ?

--
Robin Dunn
Software Craftsman
http://wxPython.org

thanks Robin, you pointed me to solution.

  1. Document should be written in lowercase:

` self.Html.document.SaveFile()

`

  1. through dir(self.Html.document) , I found
    that Save and SaveAs exists as methods

  2. Save produces an error

Traceback (most recent call last):

File “D:\Data_Python_25\TO_aggregatie\TO_apps\TOA__Patient_all.py”,
line 303, in _On_IE_Close

self.Html.document.Save ()

_ctypes.COMError: (-2146823683, None, (u’The Save method or property is
not available because this document is in another application.’,
u’Microsoft Word’, u’P:\Program Files\Microsoft
Office\Office10\1033\wdmain10.chm’, 37373, None))

So it looks that it’s not allowed to use the Save method from here

  1. With all this knowledge, some googling, brought me to the idea that
    works:

` Doc_Handle = self.Html.GetHandle ()

win32api.SendMessage ( Doc_Handle, win32con.WM_ACTIVATE,

win32con.WA_ACTIVE, 0 )

SendKeys.SendKeys ( '^s' )

`

5 Another idea that should work, but I couldn’t test it, because I
don’t know the value ord(CTRL)

` win32api.SendMessage ( Doc,
winc32con.WM_KEYDOWN, ord(CTRL), 0 )

win32api.SendMessage ( Doc, winc32con.WM_KEYDOWN, ord('S'),  0 )

win32api.SendMessage ( Doc, winc32con.WM_KEYDOWN, ord('S'),  0 )

win32api.SendMessage ( Doc, winc32con.WM_KEYUP,   ord('S'),  0 )

win32api.SendMessage ( Doc, winc32con.WM_KEYUP ,  ord(CTRL), 0 )

`

thanks,

Stef Mientki

···

On 29-03-2010 21:50, Robin Dunn wrote:

IIRC when IE loads an ActiveX control like this then the IE window’s
Document property will expose the API of the activeX object (Word in
this case). So if Word exposes some API function like SaveFile (I have
no idea if it does or not) then you should be able to get to it like
this:

self.Html.Document.SaveFile()

Hope that helps.

Hello Stef and Robin. I realize this question is ancient, but is there any chance you could post the key lines of the code you used to embed a Word document in wxPython? I have been struggling with this for a few days and I am unable to make any progress. I summarized what I have done at Embedding MS Word in a wxPython application. I really appreciate it. Thank you.