CalvinGraham
Board Regular
- Joined
- Jan 27, 2010
- Messages
- 67
This has been driving me demented. I've been putting together a macro that pulls data from Google Finance but every time, it's adding more and more name ranges. I'm trying to pull it through as "ExternalQuery" but it keeps calling it "ExternalQuery_1" , "ExternalQuery_2" etc and when I go to rename it chucks out the usual "A query with this name already exists on this sheet" even though I'm actively removing them. I've tried restarting the application, manually removing names, using code to remove names and it still insists on adding numbers due to non-existant names.
Code:
'Web query
With ThisWorkbook
For Each nQuery In Names
If IsNumeric(Right(nQuery.Name, 1)) Or nQuery.Name = "ExternalQuery" Then
nQuery.Delete
End If
Next nQuery
End With
With ActiveSheet.QueryTables.Add(Connection:="URL;" & TheQuery, Destination:=Range("TheQueryAnchor"))
.BackgroundQuery = True
.TablesOnlyFromHTML = False
.Refresh BackgroundQuery:=False
.SaveData = False
.Name = "ExternalQuery"
End With