+ Reply to Thread
Results 1 to 3 of 3

Importing most recent file

  1. #1
    wrcaz
    Guest

    Importing most recent file

    I need to import data (txt file) that changes often. Each time it changes
    the name changes based on the time stamp. How can I import the most recent
    filewith macro or VBA?

  2. #2
    Forum Contributor
    Join Date
    08-07-2004
    Location
    Ohio, USA
    Posts
    114
    You will have to set up a filesystemobject to get the createdate from the files in the specified directory.

  3. #3
    Tom Ogilvy
    Guest

    Re: Importing most recent file

    You can try something like this:

    Dim dt as Date, dtMax as Date
    Dim sPath as String, sName as String
    Dim sMax as String, bk as Workbook
    sPath = "C:\MyFiles\" '<= change to your directory
    sName = dir(sPath & "*.txt")
    dtMax = 0
    sMax = ""
    do while sName <> ""
    dt = fileDateTime(sPath & sName)
    if dt > dtMax then
    sMax = sName
    dtMax = dt
    end if
    Loop
    set bk = Workbooks.Open(sPath & sMax)

    --
    Regards,
    Tom Ogilvy


    "wrcaz" <[email protected]> wrote in message
    news:[email protected]...
    > I need to import data (txt file) that changes often. Each time it changes
    > the name changes based on the time stamp. How can I import the most

    recent
    > filewith macro or VBA?




+ Reply to Thread

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