2023-02-14 06:34来源:m.sf1369.com作者:宇宇
打开EXCEL文档,全选,复制,打开记事本,粘贴
使用以下代码即可实现:
Sub test()
Dim reg As Object
Dim wjm As String
Set reg = CreateObject(vbscript.regexp)
With reg
.Global = True
.Pattern = {id.*?}
End With
wjm = Dir(ThisWorkbook.Path & \*.txt)
m = 2
Do While wjm <>
txtm = ThisWorkbook.Path & \ & wjm
Open txtm For Input As #1
Do While Not EOF(1)
Line Input #1, ss
If Left(Trim(ss), 4) = list Then
ss = Replace(ss, Chr(13), Chr(10) & Chr(13))
Set mathcs = reg.Execute(ss)
For i = 0 To mathcs.Count - 1
s = Replace(mathcs(i), , )
s = Replace(s, :, ,)
xm = Split(s, ,)
For j = 1 To 3
Cells(m, j + 1) = xm(j * 2 - 1)
Next
For j = 4 To 5
Cells(m, j + 1) = xm(j * 2 + 1)
Next
Cells(m, 1) = wjm
m = m + 1
Next
Exit Do
End If
Loop
Close #1
wjm = Dir
Loop
End Sub
试一下,点击整张工作表的全选按钮,也可以用快捷ctrl+a,然后鼠标右键,----设置单元格格式,试试吧,