Nov-22-2021, 09:44 AM
(This post was last modified: Nov-23-2021, 07:00 AM by Yoriz.
Edit Reason: Added code tags
)
I want to replace the contents in my Excel cells. I tried the below 2 codes. But both doesn't work
Thanks
Code 1 :Same Error when I tried with Find or Replace.
Code 2 No Error but no replace occurred.
Thanks
Code 1 :Same Error when I tried with Find or Replace.
AttributeError: 'function' object has no attribute 'Execute'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import win32com.client as w3c xl = w3c.DispatchEx( "Excel.Application" ) wb = xl.Workbooks. Open (Filename = file_location, ReadOnly = False , UpdateLinks = 0 , IgnoreReadOnlyRecommended = True ) ws = wb.Worksheets( "Sheet1" ) ws.Activate ws.Cells.Find( "'*[Test.xlsx]Sheet4'" ) ws.Cells.Replace( "'Sheet4'" ) #ws.Cells.Find.Execute #ws.Cells.Replace.Execute wb.Close(SaveChanges = True ) del wb |
1 2 3 4 5 6 7 8 9 |
l = ws.Cells.Find (What = "'*[PYTHON_Use_ONLY.xlsx]Cutoffs'" , LookAt = w3c.constants.xlPart, SearchOrder = w3c.constants.xlByRows, MatchCase = False , SearchFormat = False ) print (l) - - > - 2146826246 j = ws.Cells.Replace (What = "'Cutoffs'" , LookAt = w3c.constants.xlPart, SearchOrder = w3c.constants.xlByRows, MatchCase = False , SearchFormat = False , ReplaceFormat = False , FormulaVersion = w3c.constants.xlReplaceFormula2) print (j) - - > True |