Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default File Properties

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default File Properties

Option Explicit

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

Set Res = Range("A1") 'upper left corner of Result range

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.getfolder("C:\test\")
Set fc = f.Files

i = 0

With Res

For Each fl In fc

If UCase(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

.Offset(i, 0).Value = Left(FirstLine, 8)
.Offset(i, 1).Value = Mid(FirstLine, 9, 6)
.Offset(i, 1).NumberFormat = "000000"
.Offset(i, 2).Value = Mid(ln, 9, 6)
.Offset(i, 2).NumberFormat = "000000"
.Offset(i, 3).FormulaR1C1 = "=RC[-1]-RC[-2]+1"
.Offset(i, 3).NumberFormat = "0"
.Offset(i, 4).Value = fl.datelastmodified
i = i + 1
End If
Next fl
.Offset(0, 4).EntireColumn.AutoFit
End With

End Sub



--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Little Penny" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default File Properties


WOW

Thanks Bob....




On Sun, 2 Dec 2007 23:38:56 -0000, "Bob Phillips"
wrote:

Option Explicit

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

Set Res = Range("A1") 'upper left corner of Result range

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.getfolder("C:\test\")
Set fc = f.Files

i = 0

With Res

For Each fl In fc

If UCase(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

.Offset(i, 0).Value = Left(FirstLine, 8)
.Offset(i, 1).Value = Mid(FirstLine, 9, 6)
.Offset(i, 1).NumberFormat = "000000"
.Offset(i, 2).Value = Mid(ln, 9, 6)
.Offset(i, 2).NumberFormat = "000000"
.Offset(i, 3).FormulaR1C1 = "=RC[-1]-RC[-2]+1"
.Offset(i, 3).NumberFormat = "0"
.Offset(i, 4).Value = fl.datelastmodified
i = i + 1
End If
Next fl
.Offset(0, 4).EntireColumn.AutoFit
End With

End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
File Properties TerryTutor Excel Discussion (Misc queries) 2 August 30th 07 06:06 PM
Properties transferring from excel cells to word file properties lubo Excel Programming 4 July 12th 05 11:24 AM
Get File Properties Jos Vens Excel Programming 2 February 10th 04 12:03 AM
How do I get the file properties? Guy Cohen Excel Programming 4 January 30th 04 09:31 AM
Set properties in an XLS file.. S Ayyar Excel Programming 0 December 9th 03 08:51 PM


All times are GMT +1. The time now is 03:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"