Re: [VBA ] 請問怎麼累計

作者: Yaiba (緋心刀刃)   2014-12-28 04:10:02
Option Explicit
Private Const ForReading As Integer = 1
Private lRow As Long
Sub ReadtxtFiles()
Dim sReadPath As String
Dim FSO As Object
Dim Fdr As Object
Dim Fles As Object
Dim Fle As Object
lRow = 0
sReadPath = ThisWorkbook.Path & "\"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Fdr = FSO.GetFolder(sReadPath)
Set Fles = Fdr.Files
For Each Fle In Fles
If UCase(Fle.Name) Like "*.TXT" Then
Call ProcessFile(Fle)
End If
Next
Set FSO = Nothing
End Sub
Sub ProcessFile(FL)
Dim FSO As Object
Dim Fot As Object
Dim sLineData As String
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Fot = FSO.OpenTextFile(FL, ForReading, False)
Do Until Fot.AtEndOfStream
sLineData = Fot.ReadLine
If sLineData Like "C 24 *" Then
lRow = lRow + 1
Cells(lRow, "A") = sLineData
Cells(lRow, "B") = Dir(FL)
End If
Loop
Fot.Close
Set Fot = Nothing
End Sub

Links booklink

Contact Us: admin [ a t ] ucptt.com