Thread
:
Query Tables naming not going to plan...
View Single Post
#
6
Posted to microsoft.public.excel.programming
George
external usenet poster
Posts: 347
Query Tables naming not going to plan...
Thanks for the reply Don, however my problem comes about from Excel appending
stuff to the name that I tell it to call the Query. I've been able to use
Joel's suggestion of looping through each name to find the query, then
refresh it...however there's still no resolution on why Excel is appending
this "_1" to my query name when I set it!
It's pretty late in the day for me in the UK (to still be at work anyway) so
I'll catch up with this tomorrow. I've kind of solved the problem, albeit in
a kludgey fashion, so hey-ho - chalk that one up to experience and move on :-)
George
"Don Guillett" wrote:
I'm not quite sure of what you are doing but perhaps you could DELETE the
name of the existing external query and then your add works. OR, if a
continuing query, establish the queryrecord a macro while refreshing to see
what is happening and then always refresh... Just a couple of thoughts.
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
"George" wrote in message
...
Joel - thanks for the response although it doesn't quite answer my
question.
Essentially I only want one query on the sheet (the one originally created
called PDEnglandWebQuery) and if the
VB
macro detects this query as being
present then it refreshes the query, rather than creating a new one.
Of course I could detect the presence of it by using Instr, but I was
rathr
hoping for a more elegant solution, or a fix for the appending of the
underscored number. If Excel automatically adds this, and there's nothing
I
can do about it, I guess I'll have kludge it but I'd rather get to a
neater
solution if one is available :-)
George
"Joel" wrote:
The Query names are named ranges you can look at by going to worksheet
menu
Insert - Name - Define or from Files - properties - Contents
You can search the name ranges in a macro using the macro below
Sub getname()
Lookup = "PDEnglandWebQuery"
Set nms = ActiveWorkbook.Names
For r = 1 To nms.Count
If InStr(nms(r).Name, Lookup) 0 Then
End If
Next
End Sub
"George" wrote:
Hi everyone, I'm using Query Tables to grab some data from our
corporate
intranet and it's all working very well apart from one minor
problem...each
query gets "_x" added to the name, where x is a number (starting at
one).
The code for the QueryTable is as follows...essentially I have code
before
this to check if we already have a Query open on the sheet and it
refreshes
it rather than creating a new one...
Set qt = ws.QueryTables.Add(connection, ws.Range("A1"))
With qt
.name = "PD" & tabName & "WebQuery"
.FieldNames = True
.PreserveFormatting = False
.RefreshStyle = xlOverwriteCells
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.Refresh BackgroundQuery:=True
End With
"tabName" is just something to keep a track of which sheet we are
on...values can be anything you want (think countries).
When I create a QueryTable on each sheet in this way I get (for
example):
PDEnglandWebQuery_1
PDAmericaWebQuery_1
...and so on
My refresh criteria is looking for the name set in the qt
("PDEnglandWebQuery") but obviously doesn't find it because of the _1.
Any suggestions on what I'm doing wrong?
Thanks
George
Reply With Quote
George
View Public Profile
Find all posts by George