Results 1 to 3 of 3

Thread: Read File Based on Date VBA
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    May 2019
    Posts
    11
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Read File Based on Date VBA

    Hi. I need to read a file, based on latest date. Using VBA. I really don't know how to do since before this I only put exact name of the filename.

    I know how to do it using vb.net, I do like this,
    Code:
     Dim stamp As String =
                  DateTime.Now.ToString("yyyyMMdd", CultureInfo.InvariantCulture)
    
    
            Dim TEXTfylname As String = "MB52_" & stamp & ".xlsx"
            Dim txtfile As String = localPath & TEXTfylname
    I really need to know how to read it using vba.

    Thanks all.

    Ps: I am beginner to macro.

  2. #2
    Board Regular
    Join Date
    Mar 2015
    Posts
    3,907
    Post Thanks / Like
    Mentioned
    72 Post(s)
    Tagged
    7 Thread(s)

    Default Re: Read File Based on Date VBA

    You may be able to get the string you require using VBA function FILEDATETIME

    this link shows you what the function returns etc
    https://www.techonthenet.com/excel/f...ledatetime.php

  3. #3
    Board Regular
    Join Date
    Mar 2015
    Posts
    3,907
    Post Thanks / Like
    Mentioned
    72 Post(s)
    Tagged
    7 Thread(s)

    Default Re: Read File Based on Date VBA

    Reading OP again. I think this is what you want

    Code:
    Sub DateStamp()
        Dim stamp   As String, TEXTfylname As String, txtfile As String
        
        stamp = Format(Now, "yyyymmdd")
        TEXTfylname = "MB52_" & stamp & ".xlsx"
        txtfile = CurDir() & "\" & TEXTfylname              'possibly
    Debug.Print txtfile
        txtfile = ActiveWorkbook.Path & "\" & TEXTfylname   'or maybe this
    Debug.Print txtfile
    
    End Sub

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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