Macro to delete all exernal data connections

hyperdreamz

New Member
Joined
Sep 30, 2004
Messages
11
Hi All

I am trying to write a macro to delete all connections from a very large excel file

I created this file by using a Macro to extract data from a external data source (url's listed on a sheet)

The issue is the 1000+ connections on this file make it next to impossible to operate

I cannot recreate the file

Need some help with a macro to delete all connections in all sheets in a given work book.

Sample :http://www.4shared.com/file/95922031/b7611f8f/Book1.html


Macro used :


Sub Dump()

Dim myURL

Sheets("Sheet1").Select
ActiveCell.Offset(1, 0).Select

myURL = Worksheets("Sheet1").Range(ActiveCell.Address).Text

Sheets("Sheet2").Select
Range("A65536").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select

With ActiveSheet.QueryTables.Add(Connection:= _
"URL;" & myURL, _
Destination:=Range(ActiveCell.Address))
.BackgroundQuery = False
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery:=False
.PreserveFormatting = False
.SaveData = True

.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
'.WebTables = "9"
.WebPreFormattedTextToColumns = False
.WebConsecutiveDelimitersAsOne = False
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
'.Refresh BackgroundQuery:=False

End With

Dim nName As Name
For Each nName In Names
If InStr(1, nName.RefersTo, "#REF!") > 0 Then
nName.Delete
End If
Next nName

End Sub


URL's on sheet1:

http://archive.corewebprogramming.com/Chapter2/Simple-Table.html
http://archive.corewebprogramming.com/Chapter2/Simple-Table.html
http://archive.corewebprogramming.com/Chapter2/Simple-Table.html
http://archive.corewebprogramming.com/Chapter2/Simple-Table.html
 
Last edited:

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Maybe this?

Sub deletedconns()

For i = 1 To ActiveWorkbook.Connections.Count
If ActiveWorkbook.Connections.Count = 0 Then Exit Sub
ActiveWorkbook.Connections.Item(i).Delete
i = i - 1
Next i

End Sub
 
Upvote 0
Hey smiths87

Thanks for the input. Your solution worked. But a friend reccomended this (PFB) approach that seemed to run faster.


Dim Sh As Worksheet, xNazwa As Object
Dim xConect As Object


For Each xConect In ActiveWorkbook.Connections
If UCase(xConect.Name) Like "*" Then xConect.Delete
Next xConect

For Each Sh In ActiveWorkbook.Worksheets
For Each xNazwa In Sh.Names
xNazwa.Delete
Next xNazwa
Next Sh
 
Upvote 0
I use this one.

sub delete_Connections()
do while activeworkbook.connections.count > 0
activeworkbook.connections.item(activeworkbook.connections.count).delete
loop
end sub
 
Upvote 0
I use this one.

sub delete_Connections()
do while activeworkbook.connections.count > 0
activeworkbook.connections.item(activeworkbook.connections.count).delete
loop
end sub

A long time ago I know, but just what I was looking for! :biggrin:
Cheers
B
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top