I am trying to open an existing Excel 2013 file, add data and then save it(same name) and then close it and then close Excel. The code will open the file, select the correct worksheet and write the data, but when I try save it I get an attribute error. Am I missing a library or something? Here is the code:
import win32com.client as win32
def Inventory_Status():
excel = win32.gencache.EnsureDispatch('Excel.Application') # opens Excel
wb = excel.Workbooks.Open(r'C:/pytest/Test.xlsx') # opens "Test" file
wb.Sheets(2).Select() # select 2nd worksheet "Aisle_2"
excel.Visible = True
excel.Range("A1").Select()
excel.ActiveCell.Value = "1234" # Fill in test data #
wb.save()
wb.Close()
excel.Quit()
Inventory_Status()
raise AttributeError("'%s' object has no attribute '%s'" % (repr(self), attr))
AttributeError: '<win32com.gen_py.Microsoft Excel 15.0 Object Library._Workbook instance at 0x5901424>' object has no attribute 'save'
raise
line in your post? Is that in your script? Did that get printed when you ran your script?