Results 1 to 1 of 1

creating batch files for each item in combobox

Threaded View

bg_enigma1 creating batch files for each... 11-27-2012, 04:54 PM
  1. #1
    Registered User
    Join Date
    05-16-2012
    Location
    Utah
    MS-Off Ver
    Excel 2010
    Posts
    31

    creating batch files for each item in combobox

    Hello Excel Forum-ers

    Back again with a question.

    I am working on creating batch files to setup IP Config settings (NET SH _____) I currently have a combobox that is dynamically created by visible rows of a filter.

    right now, when the userform pops up I click on the dropdown and select a servername that appears. When I click the servername it populates textboxes on the form with IP address, DNS, Gateway, WINS, etc. from the excel worksheet.

    If I click on my "Batch" command button it will run my scripts to create a batch file containing those settings. however, I want another button that can just go through and create batch files of each server in the combobox without me having to click on each one by itself. make sense?

    Below is all the code associated with my project. ***THIS ATTACHMENT IS THE SCREENSHOT OF THE USERFORM***
    network.png
    Really my biggest problem is I don't know how to make this work in a loop or using something like "next"...

    Dim FindString As String
    Dim Rng As Range
    
    Private Sub ComboBox1_Change()
    FindString = Me.ComboBox1.Value
                            
        If Trim(FindString) <> "" Then
            With Sheets("Migrations").Range("E:E")
                Set Rng = .Find(what:=FindString, _
                                After:=.Cells(.Cells.Count), _
                                LookIn:=xlValues, _
                                lookat:=xlWhole, _
                                SearchOrder:=xlByRows, _
                                SearchDirection:=xlNext, _
                                MatchCase:=False)
                If Not Rng Is Nothing Then
                    Rng.Select
                    frm_Net_Script.Text_Server_Name.Value = Range("E" & ActiveCell.Row)
                    frm_Net_Script.Text_IP.Value = Range("M" & ActiveCell.Row)
                    frm_Net_Script.Text_Subnet = Range("N" & ActiveCell.Row)
                    frm_Net_Script.Text_Gateway = Range("O" & ActiveCell.Row)
                    frm_Net_Script.Text_DNS1 = Range("P" & ActiveCell.Row)
                    frm_Net_Script.Text_DNS2 = Range("Q" & ActiveCell.Row)
                    frm_Net_Script.Text_DNS3 = Range("R" & ActiveCell.Row)
                    frm_Net_Script.Text_Suffix_1 = Range("S" & ActiveCell.Row)
                    frm_Net_Script.Text_Suffix_2 = Range("T" & ActiveCell.Row)
                    frm_Net_Script.Text_wins_1 = Range("U" & ActiveCell.Row)
                    frm_Net_Script.Text_wins2 = Range("V" & ActiveCell.Row)
        
                Else
                    MsgBox "Server Not Found"
                    Exit Sub
                End If
            End With
        End If
                                
    End Sub
    
    Private Sub Command_clear_Click()
    Me.Text_Server_Name.Value = ""
    Me.Text_IP.Value = ""
    Me.Text_Subnet.Value = ""
    Me.Text_Gateway.Value = ""
    Me.Text_Suffix_1.Value = ""
    Me.Text_Suffix_2.Value = ""
    Me.Text_wins_1.Value = ""
    Me.Text_wins2.Value = ""
    Me.Text_DNS1.Value = ""
    Me.Text_DNS2.Value = ""
    Me.Text_DNS3.Value = ""
    End Sub
    
    Private Sub Command_Create_Click()
    
    Dim strName, strDate As String
    strName = frm_Net_Script.Text_Server_Name.Value
    strDate = Sheets("Migrations").Range("A" & ActiveCell.Row).Value
    ' Set FileName for bat file
    
    'FileName = "C:\AllShare\" & Format(Now(), "dd_mm_yyyy") & "_" & strName & "_IP_Script" & ".bat"
    FileName = "C:\scripts\" & Format(Now(), "dd_mm_yyyy") & "_" & strName & "_IP_Script" & ".bat"
    
    
    Dim FileNumber As Integer
    Dim retVal As Variant
    
    FileNumber = FreeFile
    Open FileName For Output As #FileNumber
    
    Print #FileNumber, "@echo off"
    Print #FileNumber, ""
    Print #FileNumber, TextBox2.Value
    Print #FileNumber, ""
    Print #FileNumber, "set varip=" & Me.Text_IP.Value
    Print #FileNumber, "set varsm=" & Me.Text_Subnet.Value
    Print #FileNumber, "set vargw=" & Me.Text_Gateway.Value
    Print #FileNumber, "set vardns1=" & Me.Text_DNS1.Value
    Print #FileNumber, "set vardns2=" & Me.Text_DNS2.Value
    Print #FileNumber, "set vardns3=" & Me.Text_DNS3.Value
    Print #FileNumber, "set varwins1=" & Me.Text_wins_1.Value
    Print #FileNumber, "set varwins2=" & Me.Text_wins2.Value
    Print #FileNumber, ""
    Print #FileNumber, TextBox1.Value
    
    Close #FileNumber
    
    ' Run this batch file
    
    'retVal = Shell(FileName, vbMinimizedFocus)
    
    ' Delete this batch file
    
    'Kill FileName
    
    
    End Sub
    
    
    Private Sub Label8_Click()
    
    End Sub
    
    Private Sub UserForm_Initialize()
    TextBox1.Visible = False
    
    Dim rCell As Range, rVisibles As Range
     
    With Sheet10
        Set rVisibles = .Range("E7", .Cells(Rows.Count, "E").End(xlUp)).SpecialCells(12)
    End With
    For Each rCell In rVisibles
        
        frm_Net_Script.ComboBox1.AddItem rCell.Value
    
    Next rCell
    'TextBox1.Value = Module2.TXTStr("C:\AllShare\config.txt")
    'TextBox2.Value = Module2.TXTStr("C:\Allshare\deleteip.txt")
    TextBox1.Value = Module2.TXTStr("C:\scripts\config.txt")
    TextBox2.Value = Module2.TXTStr("C:\scripts\deleteip.txt")
    End Sub
    Thanks in Advance
    Last edited by bg_enigma1; 11-27-2012 at 05:00 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1