Results 1 to 2 of 2

Query.add issue

Threaded View

  1. #1
    Registered User
    Join Date
    11-13-2005
    Posts
    21

    Query.add issue

    I am wrinting a macro to import data from a text file. I thought it would be a simple record macro and go. Everything works fine except for one aspect that I have been unable to figure out. I have an excel file that I would like to import a file into on a daily basis. The thing that I cannot figure out is when I do the import, it shifts the previous imports over by the width of the new import.

    So the macro has the first blank row set as the destination for the query.add. The first run imports the data into A1. Assume there are 5 rows and 5 columns af data. The next run will put the data at A6, but it will shift rows 1 through 5 over by 5 columns. Each time I run the macro it will go down the correct 5 rows, but everything gets shifted right 5 columns.

    I am assuming this has something to do inherently with the "add" part. Is there someway to turn this off? If I do not use a macro, but just do two data imports by hand, the second one does not shift anything.

    Here is the code I am using. It is a straight macro recording except for the destination.

    rCount = Cells(Application.Rows.Count, 1).End(xlUp).Row
    
    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;C:\Documents and Settings\e003523\Desktop\342 bytes.txt", Destination:= _
        Cells(rCount, 1))
        .Name = "342 bytes"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 437
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = True
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = True
        .TextFileColumnDataTypes = Array(1, 1, 1, 3, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
    Thanks.
    Last edited by nakedbamboo; 10-07-2011 at 11:30 AM. Reason: adding code

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1