Forum Discussion
Name Conflict dialog while using win32com in Python
- Apr 19, 2023
My knowledge of Python is, to put it mildly, very modest, but with Excel better :)...
Based on the code you provided, it is not clear why the name conflict issue is occurring.
One possible cause could be that the AutoFilter method is creating a defined name in the workbook that conflicts with an existing name.
You could try adding some code to check for and remove any duplicate or conflicting defined names in the workbook before saving it.
Here is an example of how you could do this:
for name in wb.Names:
if name.Name == "ConflictingName":
name.Delete()
This code will loop through all the defined names in the workbook and delete any that have the name “ConflictingName”.
You can modify this code to check for and delete any duplicate or conflicting names that might be causing the issue.
My knowledge of Python is, to put it mildly, very modest, but with Excel better :)...
Based on the code you provided, it is not clear why the name conflict issue is occurring.
One possible cause could be that the AutoFilter method is creating a defined name in the workbook that conflicts with an existing name.
You could try adding some code to check for and remove any duplicate or conflicting defined names in the workbook before saving it.
Here is an example of how you could do this:
for name in wb.Names:
if name.Name == "ConflictingName":
name.Delete()
This code will loop through all the defined names in the workbook and delete any that have the name “ConflictingName”.
You can modify this code to check for and delete any duplicate or conflicting names that might be causing the issue.
- Leopold_1Apr 19, 2023Copper Contributor
Thanks NikolinoDE !
This helped a lot and solved the issue. Even though the names are not visible using the Excel names manager in the application with your approach i saw that everytime an autofilter is used a name (in this example {'Test1!_FilterDatabase'}" gets added to the workbook.
I slightly adjusted the code to delete duplicate entries after each usage of the autofilter.
seen = set() for name in wb2.Names: if name.Name in seen: name.Delete() else: seen.add(name.Name)
- NikolinoDEApr 19, 2023Gold ContributorI am glad that I could help you in your project.
I wish you continued success with Excel!