How to Rotate an IP Address With VBA
Learning how to automatically set an IP address to rotate using Visual Basic for Applications is not as difficult as you may think. Netsh.exe is a tool that can be used to configure computers using the Windows command prompt. Netsh.exe can be used to change an IP address when rotation is needed. The “Shell” function is used in VBA to run an executable program, such as the command prompt to execute Netsh.exe.
Instructions
-
-
1
Launch Microsoft Office Excel, click the the “Developer” tab and click “Visual Basic” to open the VBA Editor.
-
2
Click the “Insert” menu and click “Module” to insert a new code module.
-
-
3
Add the following code to create a new sub procedure:
Private Sub rotateIPAddress()
-
4
Define two string variables:
Dim dosCommand As String
Dim ipAddress As String -
5
Set the IP address you want to use by adding the following line of code:
ipAddress = "192.168.0.200"
-
6
Define the command to change the IP address:
dosCommand = "netsh interface ip set dns " & Chr(34) & "NIC Name" & Chr(34) & " static " & ipAddress
-
7
Execute the command using the “Shell” command:
Shell ("cmd.exe /c " & dosCommand)
-
8
Type “End Sub” to end your sub procedure and press the “F5” key to run it.
-
1
References
- Photo Credit Stockbyte/Stockbyte/Getty Images