Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4024404
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:43:04+00:00 2026-05-20T10:43:04+00:00

i would to import the last modified txt file from a directory using a

  • 0

i would to import the last modified txt file from a directory using a macro in Excel.
I have a folder which is incremented everyday by a new txt file.
The goal is to import the last txt file added in the direrctory.

I’ve already created a an Excel file with a button affected to macro.

Here is the code of macro:

Sub Import()
'
' Import Macro
' Macro saved on 02/03/2011 by StYellowknife3000
'

'
    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;C:\Folder\File_01.txt", Destination:= _
        Range("A1"))
        .Name = "File_01"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 932
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = True
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = True
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
End Sub

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:43:04+00:00Added an answer on May 20, 2026 at 10:43 am

    One way to do it is to use the Scripting.FileSystemObject and loop through all the files check their dates. Here’s some code I use to open the latest CSV in a folder

    For Each fsoFile In fsoFldr.Files
        If fsoFile.DateCreated > dtNew And fsoFile.Type = sCSVTYPE Then
            sNew = fsoFile.Path
            dtNew = fsoFile.DateCreated
        End If
    Next fsoFile
    
    Workbooks.Open sNew
    

    You can see all the code and the references you need to set here

    http://www.dailydoseofexcel.com/archives/2009/05/01/opening-the-newest-file-in-a-folder-with-vba/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Python you can do a: from a import b as c How would
I want to create a list of those files in a directory which have
I have denormalized data (coming from a file) that needs to be imported into
I'm using those 2 pieces of code from http://wiki.python.org/moin/UdpCommunication The server: import socket UDP_IP=127.0.0.1
I have following code import sys from ctypes import * from ctypes.util import find_library
Using JPA with EclipseLink, I would like to track the timestamp of the last
Followup on an answer from last night - I was hoping more comments would
I am modifying a website on wordpress (codex) and I would like to import
I would like to be able to import TFS tasks / work items into
I would like to know what is the best import strategy within django reusable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.