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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
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,978
Messages
6,122,549
Members
449,089
Latest member
davidcom

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