|
楼主 |
发表于 2024-5-5 19:33
|
显示全部楼层
Option Explicit
Sub test()
Dim strResult$(), ar, i&, j&, r&, n As Byte, iFileCount&
Dim Items As FileDialogSelectedItems, strPath$
strPath = ThisWorkbook.Path & "\"
With Application.FileDialog(1)
With .Filters
.Clear
.Add "文本文件(txt)", "*.txt"
End With
.AllowMultiSelect = True
.InitialFileName = strPath
If .Show Then Set Items = .SelectedItems Else Exit Sub
End With
iFileCount = IIf(Items.Count > 3, 3, Items.Count)
For i = 1 To iFileCount
n = FreeFile
Open Items(i) For Input As #n
ar = Split(StrConv(InputB(LOF(n), #n), vbUnicode), vbCrLf)
Close #n
ReDim strResult(1 To UBound(ar) + 1, 0)
For j = 0 To UBound(ar)
strResult(j + 1, 0) = ar(j)
Next j
With Worksheets(i)
.Columns("A").Clear
.[A1].Resize(UBound(strResult)) = strResult
End With
Next i
Set Items = Nothing
Beep
End Sub
请帮改,谢谢老师!最大文件20 |
|