Aha...thanks Bob. I'd actually got around the problem with: xlapp.ActiveSheet.Shapes.AddOLEObject(Filename=...)
But it's good to know what was wrong. Mark -----Original Message----- From: Bob Gailer [mailto:[EMAIL PROTECTED] Sent: 30 October 2006 18:25 To: Mark Norley Cc: python-win32@python.org Subject: Re: [python-win32] Excel and OLEObjects Mark Norley wrote: > Hello > > I'm trying to insert an object into an Excel sheet with the following code: > > import win32com.client > xlapp = win32com.client.Dispatch("Excel.Application") > xlapp.Visible = 1 > xlapp.Workbooks.Add() > xlapp.ActiveSheet.OLEObjects.Add(FileName = "C:\\mytext.tx"', > Link=False, DisplayAsIcon=False).Select > > But I get: AttributeError: 'function' object has no attribute 'Add' > The clue is "'function' object". This is telling you that xlapp.ActiveSheet.OLEObjects is a function. So try calling the function and applying Add to what the function returns: xlapp.ActiveSheet.OLEObjects().Add(.... The "problem" with VBA is that Function calls that take no arguments also have no (). > If I record a macro in Excel for what I want to do it comes out as: > > Sub Macro1() > ' > ' Macro2 Macro > ' Macro recorded 30/10/2006 by Mark > ' > > ' > ActiveSheet.OLEObjects.Add(Filename:="C:\mytext.txt", Link:=False, _ > DisplayAsIcon:=False).Select > End Sub > > I'm a complete COM noob...what am I doing wrong? > > Cheers > Mark > > WinXP SP2 > Python 2.4.2 > Pywin32 210 > Excel 2003 > > > -- Bob Gailer 510-978-4454 -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.1.408 / Virus Database: 268.13.17/505 - Release Date: 27/10/06 -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.408 / Virus Database: 268.13.17/505 - Release Date: 27/10/06 Send instant messages to your online friends http://uk.messenger.yahoo.com _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32