|
Option Explicit
Sub TEST()
Dim Items As FileDialogSelectedItems, strPath$
Dim strResult$(), ar, br, y&, x&, n As Byte
strPath = ThisWorkbook.Path & "\"
With Application.FileDialog(1)
With .Filters
.Clear
.Add "文本文件(txt)", "*.txt"
End With
.AllowMultiSelect = False
.InitialFileName = strPath
If .Show Then Set Items = .SelectedItems Else Exit Sub
End With
Application.ScreenUpdating = False
n = FreeFile
Open Items(1) For Input As #n
ar = Split(StrConv(InputB(LOF(n), #n), vbUnicode), " ^^")
Close #n
ReDim strResult(UBound(ar), 1)
For y = 0 To UBound(ar)
br = Split(ar(y), " ")
For x = 0 To UBound(br)
strResult(y, x) = br(x)
Next x
Next y
Cells.Clear
[A1].Resize(, 2) = Split("编号 数量")
[A2].Resize(UBound(strResult) + 1, 2) = strResult
Set Items = Nothing
Application.ScreenUpdating = True
Beep
End Sub
|
|