Get txt file date and paste in a cell

rozak

New Member
Joined
Nov 24, 2016
Messages
8
I am using this sub which prompts me to click on a .txt file so as to pull that data into Excel. How can I also grab the creation date of the selected file and paste it into cell J1 at the same time? I was hoping FileDateTime() would do this for me but apparently not.
Thanks in advance


VBA Code:
Public Sub ImportTextComma()

    Dim Openthefile As Variant
    Dim FFtype As String
    Dim sht As Worksheet
    Dim lr As Long

    lr = Cells(Rows.Count, "B").End(xlUp).Row
    Range("A1:J" & lr).Clear
    Set sht = ThisWorkbook.Sheets("Database")
    FFtype = "Text Files (*.txt; *.csv), *.txt; *.csv"
    Openthefile = Application.GetOpenFilename(FFtype)
    If Openthefile = False Then
        MsgBox "No file selected."
    Else
        ImportCommaSValue Openthefile, 1, sht.Range("A2")
    End If

Openthefile.FileDateTime().Value = sht.Range("J1")

End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
When posting vba code in the forum, please use the available code tags, not Quote tags. My signature block below has more details. I have changed the tags for you this time. 😊
 
Upvote 0
Your are close: try this.

VBA Code:
sht.Range("J1") = FileDateTime(Openthefile)
 
Upvote 0
Solution

Forum statistics

Threads
1,214,940
Messages
6,122,356
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top