Home |
Search |
Today's Posts |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
SUM NUMBERS WITH APPENDING TEXT | Excel Discussion (Misc queries) | |||
Appending excel worksheets | Excel Worksheet Functions | |||
QueryTables Add | Excel Programming | |||
Pasting records into Excel with QueryTables | Excel Programming |