How To Log User's IP Address?

CaliKidd

Board Regular
Joined
Feb 16, 2011
Messages
173
I'd like to write some Excel VBA code that identifies the user's IP address and saves that info to a cell in a spreadsheet. Any ideas?
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Thanks, the code worked, but the IP that it found is the IP assigned by my router. I'd like to grab the IP address I use to access the internet. Any ideas?
 
Upvote 0
OK, Blade Hunter, I like the scrape link idea. It provides the IP address I want to capture, but I'm not sure how to write the VBA code to grab this from the webpage and then save it into a worksheet cell. Can you assist?
 
Upvote 0
Web query seems like an overkill for this, but one possible way

Code:
Sub Test()
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;http://www.whatismyip.com/automation/n09230945.asp", Destination:=Range( _
        "$A$1"))
        .Name = "n09230945_1"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlEntirePage
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
End Sub
 
Upvote 0
Using the scrape link from Blade Hunter in xmlhttp (thx to Matty Vidas for dragging me off IE)
Code:
Sub IP()
    Dim objxmlhttp
    Dim strHtml As String
    Set objxmlhttp = CreateObject("Microsoft.XMLHTTP")
    With objxmlhttp
        .Open "GET", "http://www.whatismyip.com/automation/n09230945.asp"
        .Send
        Do While .readystate <> 4
        DoEvents
        Loop
        strHtml = .responseText
    End With
    MsgBox strHtml
End Sub
 
Upvote 0
Wonderful! Both examples work, so I have not just one solution, but two ways of getting this done! :) Thank you both for taking the time to help me out. I will study the code logic from both examples to edify my VBA skills.
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,762
Members
452,940
Latest member
rootytrip

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