[算表] 请问怎么累计

楼主: antemw (我会很有礼貌)   2014-11-11 10:37:43
※ [本文转录自 Visual_Basic 看板 #1KO9IGN2 ]
作者: antemw (我会很有礼貌) 看板: Visual_Basic
标题: [VBA ] 请问怎么累计
时间: Mon Nov 10 18:33:47 2014
请帮我看看程式码
如果我有违反版规,请帮我删除
以下是两个程序的程式码
主要目的是要搜寻相同资料夹中的txt档
搜寻出 C 24 后面的字串 同时输出档名
C 24 后面的字串Print在 Cell(1,A)
档名Print在 Cell(1,B)
接着读取第二个txt档
C 24 后面的字串Print在 Cell(2,A)
档名Print在 Cell(2,B)
不知道为什么
他会一直Print在 Cell(1,A) 跟 Cell(1,B)
可能我一时迷失
搞了一天了 拜托各位 T_T
- - - - - - - - - - - - - - - - - - - - - - - - -
Sub ReadtxtFiles()
Dim lRow As Long
Dim FSO As Object
Dim FL As Object
Dim Fle As Object
rpath = ThisWorkbook.Path & "\"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Fdr = FSO.GetFolder(rpath)
Set Fle = Fdr.Files
For Each FL In Fle
If UCase(FL.Name) Like "*.TXT" Then ProcessFile FL
Next
Set FSO = Nothing
lRow = 0
End Sub
Sub ProcessFile(FL)
Dim Fot As Object
Dim FRL As String
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Fot = FSO.OpenTextFile(FL, 1, False)
Do Until Fot.AtEndOfStream
FRL = Fot.ReadLine
If FRL Like "C 24 *" Then
lRow = lRow + 1
Cells(lRow, "A") = FRL
Cells(lRow, "B") = Dir(FL)
End If
Loop
Fot.Close
Set Fot = Nothing
End Sub
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
作者: soyoso (我是耀宗)   2014-11-11 12:35:00
这是因为每跳到procesfile程序时lRow就会重计的关系将Dim lRow as Long移到sub readtxtfiles()的上面试试http://goo.gl/pY26FF

Links booklink

Contact Us: admin [ a t ] ucptt.com