|
发表于 2016-12-26 19:41
|
显示全部楼层
本楼为最佳答案
本帖最后由 wanao2008 于 2016-12-27 20:29 编辑
请测试:
- Sub wanao()
- Dim txtLine, FileObj, TextObj, FilePath
- Dim x As Integer
- Set FileObj = CreateObject("Scripting.FileSystemObject")
- FilePath = ThisWorkbook.Path & "\33.txt"
- Set TextObj = FileObj.OpenTextFile(FilePath, 1, True)
- x = Cells(Rows.Count, "a").End(xlUp).Row
- Do While Not TextObj.AtEndOfStream
- txtLine = Trim(TextObj.readline)
- If InStr(txtLine, "interface") Then
- x = x + 1
- Cells(x, 1) = x - 1
- Cells(x, "c") = "'" & Replace(txtLine, "interface GigabitEthernet", "")
- End If
- If InStr(txtLine, "eth-trunk") Then
- Cells(x, "d") = txtLine
- End If
- If InStr(txtLine, "description") Then
- Cells(x, "i") = Trim(Replace(txtLine, "description", ""))
- End If
- If InStr(txtLine, "shutdown") Then
- Cells(x, "e") = txtLine
- End If
- Loop
- Set TextObj = Nothing
- Set FileObj = Nothing
- End Sub
复制代码
|
|