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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
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]
 

xenou

MrExcel MVP
Joined
Mar 2, 2007
Messages
16,836
Office Version
  1. 2019
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,133,715
Messages
5,660,446
Members
418,580
Latest member
JP82

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
Top