|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Public Sub tt()
- Dim fso As Object, fp$, ts As Object, fl As Object, str$, arr(1 To 1, 1 To 5)
- Dim reg As Object, i&, brr(1 To 5), n&
- With Application.FileDialog(msoFileDialogFolderPicker)
- If .Show Then
- fp = .SelectedItems(1)
- Else
- Exit Sub
- End If
- End With
- If Right(fp, 1) <> "" Then fp = fp & ""
- Set fso = CreateObject("scripting.filesystemobject")
- Set reg = CreateObject("vbscript.regexp")
- ActiveSheet.UsedRange.Offset(1, 0).Clear
- brr(1) = "sysname .+"
- brr(2) = "Comware Software, .+"
- brr(3) = "uptime is .+"
- brr(4) = "CPU usage:\r\n.+\r\n.+\r\n.+"
- brr(5) = "Used Rate: .+"
- For Each fl In fso.getfolder(fp).Files
- If fso.getextensionname(fl) = "txt" Then
- Set ts = fl.openastextstream(1)
- str = ts.readall
- ts.Close
- For i = 1 To 5
- reg.Pattern = brr(i)
- If reg.test(str) Then
- arr(1, i) = reg.Execute(str)(0)
- Else
- arr(1, i) = ""
- End If
- Next
- n = ActiveSheet.UsedRange.Rows.Count + 1
- ActiveSheet.Range("A" & n).Resize(1, 5).Value = arr
- End If
- Next
- brr(1) = "sysname "
- brr(2) = "Comware Software, "
- brr(3) = "uptime is "
- brr(4) = "CPU usage:" & Chr(13) & Chr(10)
- brr(5) = "Used Rate: "
- For i = 1 To 5
- ActiveSheet.UsedRange.Replace brr(i), ""
- Next
- ActiveSheet.UsedRange.EntireRow.AutoFit
- End Sub
复制代码
|
|