|
参与一下。。。
- Sub ykcbf() '//2024.9.11 提取数据
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- p = ThisWorkbook.Path & ""
- f = p & "1.txt"
- Set sh = ThisWorkbook.Sheets("Sheet1")
- zrr = Split(ReadUTFText(f), Chr(13))
- ReDim brr(1 To 1, 1 To 4)
- For i = UBound(zrr) To 0 Step -1
- If zrr(i) <> Empty Then
- s = Trim(WorksheetFunction.Trim(zrr(i)))
- s = Replace(Replace(Replace(s, "[", ""), "]", ""), Chr(10), "")
- b = Split(s)
- If InStr(b(0), "书名") Then
- brr(1, 1) = Replace(b(0), "书名", "")
- brr(1, 2) = Replace(b(1), "作者", "")
- brr(1, 3) = Replace(b(2), "SS号", "")
- brr(1, 4) = b(4)
- Exit For
- End If
- End If
- Next
- With sh
- .UsedRange.Offset(1).ClearContents
- .Columns(3).NumberFormatLocal = "@"
- .[a2].Resize(1, 4) = brr
- End With
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
- Function ReadUTFText(ByVal fn As String) As String
- With CreateObject("ADODB.Stream")
- .Type = 2
- .Mode = 3
- .Open
- .LoadFromFile fn
- .Charset = "UTF-8"
- .Position = 2
- ReadUTFText = .ReadText
- .Close
- End With
- End Function
复制代码
|
|