Delete connection in Excel using VBA after web scraping -


i have connection web scrapes based on dynamic link. so, cannot set fixed connection. following macro creates connection , updates worksheet.

with thisworkbook.worksheets("data").querytables.add(connection:= _         "<url redacted>", destination:=thisworkbook.worksheets("data").range("$a$1"))         .name = "datapull"         .fieldnames = true         .rownumbers = false         .filladjacentformulas = false         .preserveformatting = true         .refreshonfileopen = false         .backgroundquery = false         .refreshstyle = xlinsertdeletecells         .savepassword = false         .savedata = true         .adjustcolumnwidth = true         .refreshperiod = 0         .webselectiontype = xlentirepage         .webformatting = xlwebformattingnone         .webpreformattedtexttocolumns = true         .webconsecutivedelimitersasone = true         .websingleblocktextimport = false         .webdisabledaterecognition = false         .webdisableredirections = false         .refresh backgroundquery:=false         .delete end 

this macro runs every 1 minute update data. so, creates new connection every time runs. not want many connections exist won't used anymore. how delete connection once web scraping complete? or there way set single connection can modify based on variable. variable time intervals vary based on current time.

i looked @ option

for each qr in thisworkbook.queries     qr.delete next qr 

but there 2 other fixed connections don't want delete. new connections created have names connection, connection1, , on. there way delete connections based on name?

let's want delete connections, except connection1 , connection2, try...

dim conn workbookconnection each conn in thisworkbook.connections     if conn.name <> "connection1" , conn.name <> "connection2"         conn.delete     end if next conn 

hope helps!


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -