0

On a Mac OS, I'm trying to figure out how I can get the IP address of a website like 'www.google.com' and add it into a cell in Excel. I've written a Visual Basic Macro script that loops through every row of a spreadsheet and takes the value of column 2 (the website URL). My spreadsheet looks like this:

|----------|-------------------|--------------|
| [Button] | Website           | IP Addresses |
|----------|-------------------|--------------|
|          | www.gov.uk        | <ip_address> |
|          | www.parliament.uk | <ip_address> |
|----------|-------------------|--------------|

I would like to put the corresponding IP Adress of the website URLs in column 2 into column 3. I've tried to write a couple of examples but I get a few errors:

Example 1

Shows an alert that says "Runtime error '424': Object required".

Sub GetIPAddresses()
    For i = 2 To Rows.Count
        If IsEmpty(Cells(i, 2).Value) = False Then
            Cells(i, 3).Value = System.Net.Dns.GetIpAddress(Cells(i, 2).Value)
        End If
    Next i
End Sub

Example 2

Shows an alert that says "Compile error: Sub or Function not defined".

Sub GetIPAddresses()
    For i = 2 To Rows.Count
        If IsEmpty(Cells(i, 2).Value) = False Then
            Cells(i, 3).Value = GetIpAddress(Cells(i, 2).Value)
        End If
    Next i
End Sub
pgSystemTester
  • 8,979
  • 2
  • 23
  • 49
Joshua Waheed
  • 277
  • 4
  • 16
  • do you have 64 bit version of Excel? – Zam Feb 02 '19 at 13:10
  • @Zam I just checked and yes, I'm using a 64-bit version of Excel. – Joshua Waheed Feb 02 '19 at 13:28
  • You cannot just paste VB.NET code into VBA and expect it to work. – GSerg Feb 02 '19 at 13:33
  • @GSerg Sorry, I'm new to Visual Basic, not really sure how things work and just wanted to create a spreadsheet that converts website URLs to IP addresses. Do you know what I can do to make my script work please? – Joshua Waheed Feb 02 '19 at 13:47
  • Similar question https://stackoverflow.com/questions/37074533/canonical-how-to-call-net-methods-from-excel-vba – Zam Feb 02 '19 at 13:48
  • I have big doubt about .Net support in Excel for Mac OS X – Zam Feb 02 '19 at 13:49
  • How about using xmlhttp to call a Web API? – Kevin Feb 02 '19 at 13:58
  • Hi @Kevin, how can I do that? – Joshua Waheed Feb 02 '19 at 13:59
  • 1
    Take a look at this https://www.google.com.co/amp/s/officetricks.com/domain-to-ip-find-website-ip-address/amp/ – Ricardo Diaz Feb 02 '19 at 14:02
  • Here is an article on how to call a Web API from Excel: https://codingislove.com/excel-json/ – Kevin Feb 02 '19 at 14:03
  • I like @RicardoDiaz answer. – Kevin Feb 02 '19 at 14:06
  • Here is a [VBS script](https://gallery.technet.microsoft.com/scriptcenter/6114bbe9-5cca-402c-a903-036818bd5537) which also works – Storax Feb 02 '19 at 14:14
  • @JoshuaWaheed can please add to question subject information that you need this to be done for Mac OS X. It's really very important. – Zam Feb 02 '19 at 14:21
  • Thanks guys, I'll look into this tonight. I've been developing on a mac and have no Windows machine to test these on. I'll also have a test of the XmlHttpRequest version and will get back to you guys on what worked or didn't work for me. – Joshua Waheed Feb 02 '19 at 14:22
  • @Zam That's now done. – Joshua Waheed Feb 02 '19 at 14:23
  • Then you should also remove the tag winapi – Storax Feb 02 '19 at 14:25
  • @Storax That's also done now. – Joshua Waheed Feb 02 '19 at 14:26
  • I think your best be is going to be to run a shell command and collect the output. [This answer](https://stackoverflow.com/a/12320294/4088852) covers how to shell on a Mac (the code linked in prior comment uses `WScript`, which I highly doubt will work). As far as the command to use, I'm not familiar with Mac command line utilities, but I'm guessing it is similar enough to Linux that it will have `ping`. After that, it's just a matter of parsing the output. – Comintern Feb 02 '19 at 15:46

0 Answers0