Results 1 to 12 of 12

Macro to include date variable SOLVED

Threaded View

  1. #1
    Registered User
    Join Date
    11-02-2012
    Location
    St. Louis
    MS-Off Ver
    Excel 2007
    Posts
    33

    Macro to include date variable SOLVED

    Okay everyone I have a project I am attempting to write a macro for.... Everyday I run a process that creates a file the file name is consistent except for the fact that it adds the date to the end of the file name... So here is my issue I want to write a macro to automatically import the file without the having to pick wich file to import. I want the macro to know to look for the file with todays current date. It will be the only file in the folder I want the macro to grab the file from... I am not sure if this can even be done. Any advice/help would be greatly apprecaited. I have been working on this for a month and have not gotten very far at all. I am extremely new to macros. I am including the template which I want the file imported. As well as the code I have so far.. everytime I try to run the macro I get a runtime error 450.

    The file name will look as such HNBRMT_AGENCY_112812.txt as mentioned before the only thing that changes in the file name is the date at the end. It will always have the current date at the end of the file.
    Sub Import_test()
    
    Dim filename As String
    filename = ("C:/Data/HNBRMT_AGENCY_Format$Date,mmddyy")
    With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:Data/HNBRMT_AGENCY_Format$Date,mmddyy.txt") & filename & ",Destination:=(A11)"
    
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = False
            .RefreshPeriod = 0
            .TextFilePromptOnRefresh = False
            .TextFilePlatform = 850
            .TextFileStartRow = 1
            .TextFileParseType = xlDelimited
            .TextFileTextQualifier = xlTextQualifierDoubleQuote
            .TextFileConsecutiveDelimiter = False
            .TextFileTabDelimiter = True
            .TextFileSemicolonDelimiter = False
            .TextFileCommaDelimiter = False
            .TextFileSpaceDelimiter = False
            .TextFileColumnDataTypes = Array(1, 1, 1)
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
        End With
    End Sub

    I hope I have explained this well enough!!
    Attached Files Attached Files
    Last edited by karagill; 11-30-2012 at 10:56 AM. Reason: Solved

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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