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 _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32