58 lines
1.7 KiB
HTML

<!-- 22 -->
<p>
Esta función la hice hace ya varios años, en un foro sobre temas de Excel una chica
quería saber si existia alguna forma de obtener la <a class="link" data-bs-toggle="modal" data-bs-target="#ip">IP</a>
de un equipo en Excel y fue así que hice esta solución.
</p>
<p>
El uso es muy sencillo, solo debes ingresar en cualquier celda <b>=getMyIP()</b>, una vez hecho te retornara la
información, ejemplo: <br>
</p>
<div class="img zoomable">
<img src="/static/source_imgs/excel/pst_8/1.png" alt="">
</div>
<pre><i class="bi bi-copy"> Copiar código</i>
<code class="code_lightMode">
Function getMyIP() As String
Dim objWMI As Object
Dim objQuery As Object
Dim objQueryItem As Object
Dim vIpAddress As Variant
Dim res As String
On Error GoTo ErrorHandler
' Crear objeto WMI
Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
' Consultar WMI
Set objQuery = objWMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
res = ""
' Recorrer todas las direcciones IP asignadas
For Each objQueryItem In objQuery
For Each vIpAddress In objQueryItem.IPAddress
res = res & "User IP - " & vIpAddress & vbCrLf
Next
Next
getMyIP = Trim(res)
Cleanup:
' Limpiar objetos
On Error Resume Next
Set objQueryItem = Nothing
Set objQuery = Nothing
Set objWMI = Nothing
On Error GoTo 0
Exit Function
ErrorHandler:
' Manejo de errores
res = "Error: " & Err.Description
getMyIP = res
Resume Cleanup
End Function
</code></pre>