Hi All,
I have a Network Map which is from a word document, the maps contents have
various IP address etc, i would like to know the easiest way to create a
hyperlink to these IP addressess so that when the link is clicked it would
ping the IP address.
Is there any way i could do this within Word.
Please could somone help.
Kind Rgs.
Hi Peter,
I hope your "network map" is really just text in an ordinary Word
document, not some kind of graphic representation with labels.
Otherwise this won't work...
Also, I assume that you really mean you want to "ping" the address and
not sent an HTTP request to it. That means you need to run the ping
command in a command window, not fire a hyperlink.
Run this macro to convert all the IP addresses into MacroButton
fields:
Public Sub IPmacrobuttons()
Dim oRg As Range
Dim Addr As String
Dim Fld As Field
Set oRg = ActiveDocument.Range
With oRg.Find
.MatchWildcards = True
.Text = "[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}"
.Forward = True
.Format = False
.Wrap = wdFindStop
Do While .Execute
Addr = "pingme " & oRg.Text
Set Fld = ActiveDocument.Fields.Add(Range:=oRg, _
Type:=wdFieldMacroButton, Text:=Addr, _
PreserveFormatting:=False)
Fld.Code.Style = ActiveDocument.Styles("Hyperlink")
Fld.Update
oRg.Collapse wdCollapseEnd
Loop
End With
End Sub
Then double-clicking one of the IP addresses will run this macro,
which also needs to be in the template attached to the document:
Public Sub PingMe()
Dim Addr As String
Addr = Selection.Fields(1).Code
Addr = Trim(Replace(LCase(Addr), "macrobutton pingme", ""))
Shell "cmd /K ping " & Addr, vbNormalFocus
End Sub
That will open a command window and run the ping command with the IP
address. You'll have to manually close the command window.
I've set the followup for this thread to the
microsoft.public.word.vba.general newsgroup, so please post any
further responses there.