Results 1 to 1 of 1

insert a text file with a changing name

Threaded View

  1. #1
    Registered User
    Join Date
    12-11-2012
    Location
    earth
    MS-Off Ver
    Excel 2003
    Posts
    6

    insert a text file with a changing name

    hi all,

    i have a text file that i want to insert into excel daily. the issue is the name will change each day.

    data_20121212.txt tomorrow it will be data_20121213.txt

    I have a cell on my sheet with the date part, but i can not get excel to insert the cell data into the path name.

    this is the start of the code i have now
    datename = ThisWorkbook.Worksheets("Main").Range("A3").Value
    
        Range("A1").Select
        With ActiveSheet.QueryTables.Add(Connection:= _
            "TEXT;D:\data_'datename'", Destination:=Range("$A$1") _
            )
            .Name = "data_'datename'"
            .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 = xlFixedWidth
            .TextFileTextQualifier = xlTextQualifierDoubleQuote
            .TextFileConsecutiveDelimiter = False
            .TextFileTabDelimiter = False
            .TextFileSemicolonDelimiter = False
            .TextFileCommaDelimiter = False
            .TextFileSpaceDelimiter = False
            .TextFileOtherDelimiter = "|"
            .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1)
            .TextFileFixedColumnWidths = Array(19, 349, 3, 6, 7)
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
            
        End With
    End Sub
    Any help would be great

    Moderator's Note: You have to put code tags around codes. Select the code then hit the "#" sign. I'll do it for now. Thank you.
    Last edited by vlady; 12-12-2012 at 07:56 PM. Reason: code tags

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