Getting host name with excel code.

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
I dont know why this code is not working.
Please advise. Thanks
Ped;)

Code:
Sub host_name()
Dim ClientMachineEntry As System.Net.IPHostEntry
ClientMachineEntry = System.Net.Dns.GetHostByAddress(Request.ServerVariables.Item("REMOTE_HOST"))
messagebox.Show (ClientMachineEntry.HostName)
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
This code too does not work....
Code:
[FONT=Courier New][SIZE=2][COLOR=#0000ff]sub IP_add()[/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] myHost [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][/FONT][SIZE=2][FONT=Courier New] = System.Net.Dns.GetHostName[/FONT]
[/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] myIPs [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/FONT][SIZE=2][FONT=Courier New] System.Net.IPHostEntry = System.Net.Dns.GetHostByName(myHost)[/FONT]
[FONT=Courier New]MessageBox.Show("The name of the host is = " & myIPs.HostName, "Host Name", MessageBoxButtons.OK, MessageBoxIcon.Information)[/FONT]
[/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] myIP [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Net.IPAddress [/SIZE][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][/FONT][SIZE=2][FONT=Courier New] myIPs.AddressList[/FONT]
[FONT=Courier New]MessageBox.Show("The IP address of host is = " & myIP.ToString, "Host IP Address", MessageBoxButtons.OK, MessageBoxIcon.Information)[/FONT]
[/SIZE][SIZE=2][COLOR=#0000ff][FONT=Courier New]Next[/FONT]
End sub[/COLOR][/SIZE]
 
Upvote 0
This looks like .Net code to me ... VBA and VB.Net are not quite the same thing. You could probably run this in Visual Studio Express - to get it into VBA you'd probably need to compile it down to a dll/xll and then reference the code from your VBA project.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top