absolum101
New Member
- Joined
- Feb 6, 2018
- Messages
- 11
I have been searching for a way to be able to read and write multiple files to .txt. I can currently get the most current file with a wildcard, but the other archived files are in sub-folders named by date i.e. 07072019.
I would have two dates on a sheet, say B3 and C3. B3 being start date and C3 being end date.
I tried this, but I am not able to get the date(fName) to when dir function is performed. It will see the filepath and date, but not combine.
I can access by inputting manually or opening it from the window explorer. Is there an easier way of searching and building a .txt file from several dates worth of files?
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">For x = 0 To LR - 2
Set st = Range("B2").Offset(x, 0)
Set en = Range("C2").Offset(x, 0)
stDate = DateSerial(Year(st), Month(st), Day(st))
enDate = DateSerial(Year(en), Month(en), Day(en))
Dim subPath As String
Dim Report As String
LR = LR + 1
For d = stDate To enDate
Debug.Print d
fName = Format(d, "mmddyyyy")
subPath = fPath & fName
Report = Dir(subPath & fName & "_*" & ".html")
Source = subPath And Rpt
filePath = "C:\Data\report.txt"
Textfile = FreeFile
If d = stDate Then
Open filePath For Output As Textfile
Close Textfile
Kill "C:\Data\report.txt"
Ifile = "C:\Data\report.txt"
FileCopy Source, Ifile
Source = Ifile
Else
Open filePath For Append As Textfile
Close Textfile
Ifile = "C:\Data\report.txt"
FileCopy Source, Ifile
Source = Ifile
End If
Next d
Next
CurRow = 2
Open Source For Input As #1
Do While (Not EOF())
'do stuff
CurRow = CurRow + 1
Loop
Close #1
</code>
I would have two dates on a sheet, say B3 and C3. B3 being start date and C3 being end date.
I tried this, but I am not able to get the date(fName) to when dir function is performed. It will see the filepath and date, but not combine.
I can access by inputting manually or opening it from the window explorer. Is there an easier way of searching and building a .txt file from several dates worth of files?
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">For x = 0 To LR - 2
Set st = Range("B2").Offset(x, 0)
Set en = Range("C2").Offset(x, 0)
stDate = DateSerial(Year(st), Month(st), Day(st))
enDate = DateSerial(Year(en), Month(en), Day(en))
Dim subPath As String
Dim Report As String
LR = LR + 1
For d = stDate To enDate
Debug.Print d
fName = Format(d, "mmddyyyy")
subPath = fPath & fName
Report = Dir(subPath & fName & "_*" & ".html")
Source = subPath And Rpt
filePath = "C:\Data\report.txt"
Textfile = FreeFile
If d = stDate Then
Open filePath For Output As Textfile
Close Textfile
Kill "C:\Data\report.txt"
Ifile = "C:\Data\report.txt"
FileCopy Source, Ifile
Source = Ifile
Else
Open filePath For Append As Textfile
Close Textfile
Ifile = "C:\Data\report.txt"
FileCopy Source, Ifile
Source = Ifile
End If
Next d
Next
CurRow = 2
Open Source For Input As #1
Do While (Not EOF())
'do stuff
CurRow = CurRow + 1
Loop
Close #1
</code>