L
Little Penny
I have a macro below that extracts information from a text file. How
can I also get the date and time of the date modified properties of
the files as well. And put that information in column E.
Sub GetData2()
Dim fn As String
Dim ln As String
Dim FirstLine As String
Dim Res As Range
Dim fs, f, fl, fc, s
Dim i As Long
Range("A1").Select
Set Res = Range("A1") 'upper left corner of Result range
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.getfolder("D:\Files\")
Set fc = f.Files
i = 0
For Each fl In fc
If Right(fl.path, 4) = ".TXT" Then
fn = fl.path
FirstLine = ""
Open fn For Input As #1
Do While Not EOF(1)
Input #1, ln
If FirstLine = "" Then FirstLine = ln
Loop
Close #1
Res.Offset(i, 0).Value = Left(FirstLine, 8)
Res.Offset(i, 1).Value = Mid(FirstLine, 9, 6)
Res.Offset(i, 1).NumberFormat = "000000"
Res.Offset(i, 2).Value = Mid(ln, 9, 6)
Res.Offset(i, 2).NumberFormat = "000000"
Res.Offset(i, 3).FormulaR1C1 = "=RC[-1]-RC[-2]+1"
Res.Offset(i, 3).NumberFormat = "0"
i = i + 1
End If
Next fl
Range("A1").Select
End Sub
Thanks
can I also get the date and time of the date modified properties of
the files as well. And put that information in column E.
Sub GetData2()
Dim fn As String
Dim ln As String
Dim FirstLine As String
Dim Res As Range
Dim fs, f, fl, fc, s
Dim i As Long
Range("A1").Select
Set Res = Range("A1") 'upper left corner of Result range
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.getfolder("D:\Files\")
Set fc = f.Files
i = 0
For Each fl In fc
If Right(fl.path, 4) = ".TXT" Then
fn = fl.path
FirstLine = ""
Open fn For Input As #1
Do While Not EOF(1)
Input #1, ln
If FirstLine = "" Then FirstLine = ln
Loop
Close #1
Res.Offset(i, 0).Value = Left(FirstLine, 8)
Res.Offset(i, 1).Value = Mid(FirstLine, 9, 6)
Res.Offset(i, 1).NumberFormat = "000000"
Res.Offset(i, 2).Value = Mid(ln, 9, 6)
Res.Offset(i, 2).NumberFormat = "000000"
Res.Offset(i, 3).FormulaR1C1 = "=RC[-1]-RC[-2]+1"
Res.Offset(i, 3).NumberFormat = "0"
i = i + 1
End If
Next fl
Range("A1").Select
End Sub
Thanks