MS Word and Python - how to disable SaveAs event?

Hello!

I try use Microsoft Word and OpenOffice with Python - and i have some problems. How to disable “Save As” in word from python code, or how to cancel this function when user use it? This code below doesn’t work :confused:

wxPython 2.8.4.2
Python 2.4.4

from win32com.client import DispatchWithEvents, Dispatch
import msvcrt, pythoncom
import time, sys
import types
import os
import threading
import wx
stopEvent = threading.Event()

···

###############################################################################
class WordEvents:
###############################################################################

def OnDocumentChange(self):
self.seen_events[“OnDocumentChange”] = None
print “OnDocumentChange”

def OnWindowActivate(self, doc, wn):
self.seen_events[“OnWindowActivate”] = None

print "OnWindowActivate"

def OnQuit(self):
print “OnQuit”
self.seen_events[“OnQuit”] = None
stopEvent.set()

def OnStartup(self):
print “OnStartup”

self.seen_events["OnStartup"] = None

def OnDocumentBeforeSave(self, Doc, SaveAsUI, Cancel):
print “OnDocumentBeforeSave”
print “SaveAsUI:”, SaveAsUI
if SaveAsUI:

  Cancel = True
  return
self.seen_events["OnDocumentBeforeSave"] = None

def OnDocumentBeforeClose(self):
print “OnDocumentBeforeClose”
self.seen_events[“OnDocumentBeforeClose”] = None

###############################################################################
class MyWord:
###############################################################################
def init(self):
self.wordApp
= None
self.wordDoc = None

def del(self):
pythoncom.CoUninitialize()

def Init(self):
self.wordApp = DispatchWithEvents(‘Word.Application’, WordEvents)
self.wordApp.seen_events
= {}
self.wordApp.Visible = 0
self.wordDoc = self.wordApp.Documents.Add()

def Start(self):
print “Start…”
s = self.wordDoc.Sentences(1)
s.Text = ‘Hello world !’

self.wordDoc.Saved = 1
self.wordApp.Visible = 1

def WaitForFinish(self):
while True:
pythoncom.PumpWaitingMessages()
try:
if not self.wordApp.Visible: # jesli zamkniecie worda to czas wyjsc

      return 0
  except pythoncom.com_error:
    pass
return 1

def Wait(self):
return self.WaitForFinish()

def Stop(self):
self.wordApp.Quit()

###############################################################################

word_ed = MyWord()
word_ed.Init()
word_ed.Start()
word_ed.Wait()

Hi,

···

-----Original Message-----
From: Wojtek P [mailto:wojtulek@gmail.com]
Sent: Thursday, December 13, 2007 4:22 AM
To: wxpython-users
Subject: MS Word and Python - how to disable SaveAs event?

Hello!

I try use Microsoft Word and OpenOffice with Python - and i
have some problems. How to disable "Save As" in word from
python code, or how to cancel this function when user use it?
This code below doesn't work :confused:

wxPython 2.8.4.2
Python 2.4.4

<snip>
<snap>

You should probably post this to the pywin32 user's group as this has more
to do with them than the wxPython group. You can join here:

http://mail.python.org/mailman/listinfo/python-win32

Mike