hi
you didn't really give enough info to tell what's really wrong.
posting your code would be very helpful.
but from what you did post, it sounds like you are trying to recreate
the query each time you run it. that is really not necessary. once the
query has been created, excel assigns a name to it, a named range and
gives it properties. after that all you need to do is refresh the
query table. and 1 line of code would do it.
assuming query table is on sheet1 at cell A1.
Sub refreshit()
Sheets("sheet1").Range("A2").QueryTable.Refresh BackgroundQuery:=False
MsgBox "done"
End Sub
you could also right click the query table and from the popup, click
refresh.
so if i have it wrong, post the code you are using.
regards
FSt1
Hi,
Here is the guts of my query ... it is executed approximately 20 times
for each run.
Sub RunQuery(ByVal i As Integer, ByVal qDate As String)
Dim CmdText As String
qDate = Format(qDate, "dd-mmm-yy")
Application.DisplayAlerts = False
' Set the query command text
CmdText = _
"Get_Value('" & TagRefs.Cells(i, 1).Value & "', '" & qDate &
"')"
' Run the query
With QTable
.CommandText = CmdText
.Refresh BackgroundQuery:=False
End With
Application.DisplayAlerts = True
End Sub
Where the QTable is defined by:
Set QTable = Config.QueryTables.Add(Connection:="ODBC;Driver={AT
SQLplus};ADS=" & Server, _
Destination:=Config.Range("B1"))
Config is a worksheet and Get_Value is a named procedure: the server
name is defined elsewhere. Originally the destination for the QTable
was a defined range but after much messing around I found that Excel
doesn't seem to like named ranges on the same row as a query table -
if such a range exists the returned query is returned into a new,
Excel generated, named range in inserted columns to the left of the
previous range. If no named range exists, Excel quite happily
overwrites the names that it generates for itself.
I now remove all named ranges from the query table rows before a new
query is run - this isn't what I had originally intended and it is a
bit of a pain but it does seem to work. Any advice would still be very
welcome.
Alan