Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Why is Excel appending numbers to querytables.

Hi,

Still haven't figured this one out.. hopefully someone knows why.

Programmatically i add a querytable (name=qt) to the querytables collection
of a worksheet:

ie.
With activesheet.QueryTables.Add(Connection:="TEXT;c:\l og.txt"),
Destination:=Range("A2"))
.Name="qt"
End With

I then delete that querytable by: qt.delete.

But when i go to recreate that query table using the same name, "qt" for
some reason excel starts appending an underscore than a number to the query
table name each time i delete, then add that querytable with the same name
"qt". Ie. excel changes the name to "qt_1", or "qt_2", etc.

Anyone know why and how to stop this so taht i can use the same name "qt" to
reference the query table each time i add and delete it.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Why is Excel appending numbers to querytables.

Sorry, but a typo..

i delete the querytable (name="qt") using the reference to the querytable
returned when i added it to the worksheet querytables collection, not via
qt.delete:

qtable = activesheet.querytables.add (... )
qtable.name = "grp"

qtable.delete

when i then add that table again:
qtable = activesheet.quertables.add(..)
qtable.name = "grp"

excel actually creates teh query table with name "grp_1", or "grp_2", not
"grp" as i specified.. Why?


"Bing" wrote:

Hi,

Still haven't figured this one out.. hopefully someone knows why.

Programmatically i add a querytable (name=qt) to the querytables collection
of a worksheet:

ie.
With activesheet.QueryTables.Add(Connection:="TEXT;c:\l og.txt"),
Destination:=Range("A2"))
.Name="qt"
End With

I then delete that querytable by: qt.delete.

But when i go to recreate that query table using the same name, "qt" for
some reason excel starts appending an underscore than a number to the query
table name each time i delete, then add that querytable with the same name
"qt". Ie. excel changes the name to "qt_1", or "qt_2", etc.

Anyone know why and how to stop this so taht i can use the same name "qt" to
reference the query table each time i add and delete it.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default Why is Excel appending numbers to querytables.

Hi,
what version are you using because I cannot replicate this in 2002.
Works fine for me.

OJ

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Why is Excel appending numbers to querytables.

I'm using excel 2003.


"OJ" wrote:

Hi,
what version are you using because I cannot replicate this in 2002.
Works fine for me.

OJ


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default Why is Excel appending numbers to querytables.

Hi,
perhaps if you posted your entire routine(s) then I might be able to
help. My instincts ask me why delete and then recreate....can you not
just change the connection string and use the same table each time?

OJ



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Why is Excel appending numbers to querytables.

Hi OJ, Let me first say thanks for helping!

I suppose you could use same table, it just seemed cleaner to start from a
new querytable each time a new data file was loaded.. in any case here is the
code:

function parameters i used we
qtName="grp"
qtConnection = "TEXT;" & commaDelimitedFilenameToImport
qtSht = any worksheet
qtCell = "A2"

Run this function a few times in the same VB session and inspect the
querytable name in the worksheet querytables collection each time you this is
function is called. I created a querytable name of "grp" I noticed that
eventho i thought i was deleting the "grp" query table, when i did a
qtSht.Querytables.count it was actually incrementing by 1 each time and the
names of each query table was "grp", "grp_1", "grp_2", etc.

Public Function InitQueryTable(qtName As String, qtConnection As String,
qtSht As Worksheet, qtCell As String) _
As QueryTable

On Error Resume Next
qtSht.QueryTables(qtName).Delete
Err.Clear

Dim qt As QueryTable
Set qt = qtSht.QueryTables.Add(Connection:=qtConnection, _
Destination:=qtSht.Range(qtCell))

With qt
.Name = qtName
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
' .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1)
.TextFileTrailingMinusNumbers = True
.BackgroundQuery = False
End With
Set InitQueryTable = qt
"OJ" wrote:

Hi,
perhaps if you posted your entire routine(s) then I might be able to
help. My instincts ask me why delete and then recreate....can you not
just change the connection string and use the same table each time?

OJ


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default Why is Excel appending numbers to querytables.

Bing

I've had inconsistent results adding and deleting qts. When you create a
qt, Excel also creates a range name. Deleting the qt doesn't delete the
range name, however. If you create a qt with the same name as an existing
range name, Excel will append an incrementing digit to the end.

Based on that, you'd think you could just delete the named range when you
delete the qt, but that doesn't always work. I can't figure out what I'm
doing differently, because sometimes it does work.

The best way, in my opinion, is to not delete the qt in the first place. If
you want to change the qt, change the Connection and Commandtext properties
and Refresh it. Then you have the same qt object the whole time (with the
same name) and you just change certain aspects of it.


--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com

Bing wrote:
Sorry, but a typo..

i delete the querytable (name="qt") using the reference to the
querytable returned when i added it to the worksheet querytables
collection, not via qt.delete:

qtable = activesheet.querytables.add (... )
qtable.name = "grp"

qtable.delete

when i then add that table again:
qtable = activesheet.quertables.add(..)
qtable.name = "grp"

excel actually creates teh query table with name "grp_1", or "grp_2",
not "grp" as i specified.. Why?


"Bing" wrote:

Hi,

Still haven't figured this one out.. hopefully someone knows why.

Programmatically i add a querytable (name=qt) to the querytables
collection of a worksheet:

ie.
With activesheet.QueryTables.Add(Connection:="TEXT;c:\l og.txt"),
Destination:=Range("A2"))
.Name="qt"
End With

I then delete that querytable by: qt.delete.

But when i go to recreate that query table using the same name, "qt"
for some reason excel starts appending an underscore than a number
to the query table name each time i delete, then add that querytable
with the same name "qt". Ie. excel changes the name to "qt_1", or
"qt_2", etc.

Anyone know why and how to stop this so taht i can use the same name
"qt" to reference the query table each time i add and delete it.



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Why is Excel appending numbers to querytables.

Hi Dick, OJ,

Thanks to both of you for trying to help out. Well i have just about given
up on this one too. Like you guys said, i'll just keep the old querytable
and reinit the connection parameters.

Thanks again for helping! Very much appreciated.

Cheers,


"Dick Kusleika" wrote:

Bing

I've had inconsistent results adding and deleting qts. When you create a
qt, Excel also creates a range name. Deleting the qt doesn't delete the
range name, however. If you create a qt with the same name as an existing
range name, Excel will append an incrementing digit to the end.

Based on that, you'd think you could just delete the named range when you
delete the qt, but that doesn't always work. I can't figure out what I'm
doing differently, because sometimes it does work.

The best way, in my opinion, is to not delete the qt in the first place. If
you want to change the qt, change the Connection and Commandtext properties
and Refresh it. Then you have the same qt object the whole time (with the
same name) and you just change certain aspects of it.


--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com

Bing wrote:
Sorry, but a typo..

i delete the querytable (name="qt") using the reference to the
querytable returned when i added it to the worksheet querytables
collection, not via qt.delete:

qtable = activesheet.querytables.add (... )
qtable.name = "grp"

qtable.delete

when i then add that table again:
qtable = activesheet.quertables.add(..)
qtable.name = "grp"

excel actually creates teh query table with name "grp_1", or "grp_2",
not "grp" as i specified.. Why?


"Bing" wrote:

Hi,

Still haven't figured this one out.. hopefully someone knows why.

Programmatically i add a querytable (name=qt) to the querytables
collection of a worksheet:

ie.
With activesheet.QueryTables.Add(Connection:="TEXT;c:\l og.txt"),
Destination:=Range("A2"))
.Name="qt"
End With

I then delete that querytable by: qt.delete.

But when i go to recreate that query table using the same name, "qt"
for some reason excel starts appending an underscore than a number
to the query table name each time i delete, then add that querytable
with the same name "qt". Ie. excel changes the name to "qt_1", or
"qt_2", etc.

Anyone know why and how to stop this so taht i can use the same name
"qt" to reference the query table each time i add and delete it.




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
SUM NUMBERS WITH APPENDING TEXT spidut Excel Discussion (Misc queries) 4 January 14th 07 03:05 PM
Appending excel worksheets Rbuzard Excel Worksheet Functions 3 September 13th 05 11:57 AM
QueryTables Add Marta[_3_] Excel Programming 0 January 19th 05 05:32 PM
Pasting records into Excel with QueryTables Saul Margolis Excel Programming 3 October 6th 04 09:43 AM


All times are GMT +1. The time now is 09:47 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"