再来一下:- arrCell = Array("D37", "D38", "D39") ''需要提取的单元格
- Set fso = CreateObject("Scripting.FileSystemObject")
- For Each file in fso.GetFolder(".").Files
- If LCase(Right(file, 4)) = ".csv" Then
- Set f = fso.OpenTextFile(file, 1)
- txt = f.ReadAll : f.Close
- str = str & getCellsData(txt) & vbCrLf
- End If
- Next
-
- fso.OpenTextFile("new.csv", 2, true).Write str
- MsgBox "OK"
-
- Function getCellsData(ByVal txt)
- '' csv文本分割成数组
- arrTxt = Split(txt, vbCrLf)
- strChr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- ''建立正则表达式
- Set re = New RegExp
- ''正则表达式模式,最大支持到ZZ列
- re.Pattern = "^([a-z]{1,2})(\d+)$"
- re.IgnoreCase = true
- For i = 0 to UBound(arrCell)
- n = re.Execute(arrCell(i))(0).SubMatches(0)
- n = UCase(Right("0" & n, 2))
- n1 = InStr(strChr, Left(n, 1))
- n2 = InStr(strChr, Mid(n, 2))
- n = n1 * 26 + n2 - 1
- m = re.Execute(arrCell(i))(0).SubMatches(1) - 1
- s = s & "," & Split(arrTxt(m), ",")(n)
- Next
- getCellsData = Mid(s, 2)
- End Function
复制代码
|