|
Sub 按钮1_Click()
With Application.FileDialog(msoFileDialogFilePicker)
.InitialFileName = ThisWorkbook.Path & "\"
.Title = "请选择对应文本文件"
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "文本文件", "*.txt"
If .Show Then f = .SelectedItems(1) Else Exit Sub '
End With
str1 = ReadUTF(f)
arr = Split(str1, ":")
r = Cells(Rows.Count, 1).End(3).Row + 1
arr(0) = r - 1
For j = 1 To UBound(arr)
arr(j) = Split(arr(j), Chr(10))(0)
Next j
Cells(r, 1).Resize(1, UBound(arr) + 1) = arr
Cells(r, 8) = Split(str1, "¥")(1)
End Sub
Function ReadUTF(ByVal FileName As String) As String
With CreateObject("ADODB.Stream")
.Type = 2
.Mode = 3
.Open
.LoadFromFile FileName
.Charset = "UTF-16"
.Position = 2
ReadUTF = .ReadText
.Close
End With
End Function |
|