Word VBA to retrieve IP address “silently”

后端 未结 2 529
春和景丽
春和景丽 2021-01-13 19:06

I need to pull out the IP address into a VBA macro. This code works but the command dialogue is briefly visible which is not a good look. Can I use a modification to do it \

2条回答
  •  甜味超标
    2021-01-13 19:30

    I think this may be easier, it uses WMI.

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
    Set colItems = objWMIService.ExecQuery( _
        "SELECT * FROM Win32_NetworkAdapterConfiguration", , 48)
    For Each objItem In colItems
        If Not IsNull(objItem.IPAddress) Then
            ''Commented line
            ''Debug.Print "IPAddress: " & Join(objItem.IPAddress, ",")
            ''Message box
            MsgBox "IPAddress: " & Join(objItem.IPAddress, ",")
            ''String for later use
            strIPAddress = strIPAddress & Join(objItem.IPAddress, ",")
        End If
    Next
    ''Later
    SynapseForm.LabelIP.Caption = strIPAddress
    

提交回复
热议问题