|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
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), vbCrLf)
Close #n
ReDim strResult(UBound(ar), UBound(Split(ar(0), vbTab)))
For y = 0 To UBound(ar)
br = Split(ar(y), vbTab)
For x = 0 To UBound(br)
strResult(y, x) = br(x)
Next x
Next y
[A1].CurrentRegion.Offset(1).Clear
With [A2].Resize(UBound(strResult) + 1, UBound(strResult, 2) + 1)
.Value = strResult
End With
Set Items = Nothing
Application.ScreenUpdating = True
Beep
End Sub
|
|