|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Option Explicit
Sub test()
Dim ar, cr, i&, j&, r&, dic As Object, n As Byte
Dim strFileName$, strPath$, strFName$, iRowSize&, iPosCol&
Application.ScreenUpdating = True
Set dic = CreateObject("Scripting.Dictionary")
With [A1].CurrentRegion
.Offset(1).Clear
ar = .Resize(10 ^ 4)
For j = 1 To UBound(ar, 2)
dic(ar(1, j)) = j
Next j
r = 1
End With
strPath = ThisWorkbook.Path & "\数据源\"
strFileName = Dir(strPath & "*.txt")
Do Until strFileName = ""
strFName = Left(strFileName, InStrRev(strFileName, ".") - 1)
If dic.exists(strFName) Then
n = FreeFile: iPosCol = dic(strFName): r = 1
Open strPath & strFileName For Input As #n
cr = Split(Replace(StrConv(InputB(LOF(n), #n), vbUnicode), vbCrLf, ""), " ")
Close #n
For j = 0 To UBound(cr)
r = r + 1
ar(r, iPosCol) = cr(j)
Next j
If r > iRowSize Then iRowSize = r
End If
strFileName = Dir
Loop
[A1].Resize(r, UBound(ar, 2)) = ar
Application.ScreenUpdating = True
Beep |
评分
-
1
查看全部评分
-
|