Reputation: 31
I'm trying to use python win32 excel application in order to:
1) copy a worksheet
2) change the name of the copied worksheet
Using the following code:
from win32com.client import Dispatch
xl = Dispatch("Excel.Application")
wb = xl.Workbooks.Open('Spreadsheet.xlsx')
ws = wb.Worksheets('Sheet1')
ws.Name = 'Name of Copied Sheet'
But I get the following error:
AttributeError: 'NoneType' object has no attribute 'Name'
Upvotes: 3
Views: 6282
Reputation: 131
This is old but I did it the following way successfully, might help someone else in the future.
import win32com.client as win32
excel = win32.DispatchEx('Excel.Application')
wb = excel.Workbooks.Open(file)
wb.Worksheets(1).Name = "New Name"
Upvotes: 3