Accessing Word object model from Python COM server

Nikolai Kirsebom nikolai.kirsebom at siemens.no
Fri Nov 5 10:58:58 CET 1999


I'm using a Python COM server when testing a VBA (Word97) system.  I
would like to be able to access the Word object model from the methods
in the COM server.  Does anyone know how this can be done.

I would like the following setup:

VBA-code:
** Initialization:
Dim Srv As Object
Set Srv = CreateObject("PythonCOMserver")
Srv.SetRef Application

** Action handling:
Dim doc As Word.Document
doc = Srv.GetNew


Python COM server code:
def SetRef(self, applObj):
  self.ApplObj = appObj
  return 0

def GetNew(self):
  doc = self.AppObj.Documents.Add()
  # some additional handlnig
  return doc


When the GetNew method in the Python COM server is executed, an error
indicates that the name 'Documents' is invalid.  The self.ApplObj is
of type PyIDispatch (I think), however may it must be an 'instance' in
order to be able to access the object model.  If I instead of
accessing the object model just returns the object (self.AppObj) and
makes use of the returned object back in the VBA code, I can use the
object model - so the round-trip seems to work.

Thanks for any help/hints.

Nikolai Kirsebom







More information about the Python-list mailing list