0
I need help to remove the Excel connection, where I have an SQL query inside Excel that feeds several tabs that are inside Excel, but when I use the code below returns me with an error
conn.Delete()
File "<COMObject <unknown>>", line 2, in Delete
The code I’m using is
import win32com.client
Bases = ["customer1","customer2","customer3"]
fileDest = '//caminho/do/arquivo/final/sem/conexao'
for base in Bases:
dir = '//caminho/dos/arquivos/com/conexao{}'.format(base)
print(base)
xlapp = win32com.client.DispatchEx("Excel.Application")
wb = xlapp.Workbooks.Open(dir)
xlapp.Visible = True
wb.RefreshAll()
wb.Save()
print(base,' Atualizou')
print('\n')
print('removendo conexao')
for conn in wb.Connections: # quando chega aqui ele da erro
conn.Delete()
print('removido')
wb.SaveAs(fileDest)
xlapp.Quit()