VB-EXCEL-CFG-TO-FILE

Dim g_int_row As Integer
Dim g_ospf_int_row As Integer
Dim g_mpls_int_row As Integer
Dim g_mpls_lsp_row As Integer
Dim g_router_num As Integer

Sub get_item_row()
Dim cur_sheet As Sheets
Dim sheetname As String

'sheetname = ActiveWorkbook.Name '·µ»Ø»î¶¯¹¤×÷±¡µÄÃû³Æ
'sheetname = ThisWorkbook.Name '·µ»Øµ±Ç°¹¤×÷²¾Ãû³Æ
sheetname = ThisWorkbook.FullName '·µ»Øµ±Ç°¹¤×÷²¾Â·¾¶ºÍÃû³Æ

MsgBox ("current sheet is : " & sheetname & " Now active sheet is : " & ActiveSheet.Name)
'MsgBox ("current sheet is: " & ActiveWorkbook.Name & " " & ThisWorkbook.Name & " " & ThisWorkbook.FullName)
g_int_row = ActiveSheet.Cells(2, 16)
g_ospf_int_row = ActiveSheet.Cells(5, 16)
g_mpls_int_row = ActiveSheet.Cells(3, 16)
g_mpls_lsp_row = ActiveSheet.Cells(4, 16)
g_router_num = ActiveSheet.Cells(1, 17)

'g_int_row = Worksheets("Sheet12").Cells(1, 16)

'g_int_row = Sheet12.Cells(1, 16)
'MsgBox ("int_row is " & g_int_row & " " & g_ospf_int_row & " " & g_mpls_int_row & " " & g_mpls_lsp_row & " ")

End Sub
Sub write_cfg_to_file()
'Open "C:\work\SRLab\script\SRLab_0815.vbs" For Output As #1
Dim dat As Date
Dim mm, dd, dat2 As String

dat = Date
dat2 = Format(dat, "yyyy-mm-dd")
dd = Right(dat2, 2)
mm = Left(Right(dat2, 5), 2)
'MsgBox mm & dd & dat & dat2
'MsgBox Format(dat, "yyyy-mm-dd")

filepath = "C:\work\SRLab\script\"
Filename = "SRLab_" & mm & dd & ".cfg"
fullfile = filepath & Filename
'MsgBox fullfile

Open fullfile For Output As #1
Print #1, "# $language = ""VBScript"""; VBScript; Chr(10); ""; "# $interface = ""1.0"""; VBScript; Chr(10); "crt.Screen.Synchronous = True "; VBScript; Chr(10);
'Print #1, "Set conf = crt.OpenSessionConfiguration("135.240.146.101)")"
'Print #1, "tab0 = crt.session.Connectintab("""; ""; "/telnet 135.240.146.101 23"; ""; """)"
'Print #1, "/telnet 135.240.146.101 23 "
'Print #1, """)"
Print #1, "Dim nTabNum"
Print #1, "Dim nYearNum"
get_item_row

For i = 1 To g_router_num ' write cfg to file by router
Print #1, "/=======================================================\" & Chr(10)
Print #1, " " & "router " & i & " " & Chr(10)
Print #1, "\=======================================================/" & Chr(10)

For j = 2 To g_router_num + 1 ' from cell to cell interface
If ActiveSheet.Cells(g_int_row + i, j) <> "" Then ' interface

  Print #1, ActiveSheet.Cells(g_int_row + i, j) & Chr(10)

End If

Next

For j = 2 To g_router_num + 1 ' from cell to cell ospf
If ActiveSheet.Cells(g_ospf_int_row + i, j) <> "" Then '

  Print #1, ActiveSheet.Cells(g_ospf_int_row + i, j) & Chr(10)

End If

Next

For j = 2 To g_router_num + 1 ' from cell to cell mpls interface
If ActiveSheet.Cells(g_mpls_int_row + i, j) <> "" Then '

  Print #1, ActiveSheet.Cells(g_mpls_int_row + i, j) & Chr(10)

End If

Next

For j = 2 To g_router_num + 1 ' from cell to cell mpls lsp
If ActiveSheet.Cells(g_mpls_lsp_row + i, j) <> "" Then '

  Print #1, ActiveSheet.Cells(g_mpls_lsp_row + i, j) & Chr(10)

End If

Next
Next
'write_ip
'write_ospf
'write_mpls
'write_main

Close #1
End Sub

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章