|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test11()
- Set fso = CreateObject("scripting.filesystemobject")
- Application.ScreenUpdating = False
- a = 2
- For Each F In fso.getfolder(ThisWorkbook.Path).Files
- If InStr(F.Name, "汇总文本信息") = 0 Then
- Cells(a, 1) = Split(F.Name, ".txt")(0)
- Cells(a, 2) = ReadUTF(F)
- a = a + 1
- End If
- Next F
- Application.ScreenUpdating = True
- End Sub
- Function ReadUTF(ByVal FileName As String) As String
- With CreateObject("ADODB.Stream")
- .Type = 2 '读取文本文件
- .Mode = 3 '读写
- .Open
- .LoadFromFile FileName
- .Charset = "UTF-8" '设定编码
- .Position = 2
- ReadUTF = .ReadText
- .Close
- End With
- End Function
复制代码 |
|