| 
    
     |  | かみちゃん様、早速の回答ありがとうございます。 
 >IPアドレスを取得して、何がしたいのか、今ひとつよくわかりませんが、
 
 説明不足で申し訳ありません。
 ネットワークアダプタの設定情報をエクセルに記録し、
 また、エクセルに記録した情報を簡単に、ネットワークアダプタに
 設定したいのが、目的です。
 
 
 >他の掲示板の過去ログで申し訳ありませんが、以下のものは、参考になりませんか?
 >(「VBA IPアドレス 取得」でWeb検索すると出てきました。)
 >http://www2.moug.net/bbs/exvba/20070525000027.htm
 
 おっしゃるサイトを拝見致しまして、以下のコードで
 実行しました。
 
 Private Sub CommandButton1_Click()
 
 strComputer = "."
 
 Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
 Set colAdapters = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
 
 n = 1
 
 
 For Each objAdapter In colAdapters
 MsgBox "Network Adapter " & n
 MsgBox "================="
 MsgBox " Description: " & objAdapter.Description
 
 MsgBox " Physical (MAC) address: " & objAdapter.MACAddress
 MsgBox " Host name:       " & objAdapter.DNSHostName
 
 If Not IsNull(objAdapter.IPAddress) Then
 For i = 0 To UBound(objAdapter.IPAddress)
 MsgBox " IP address:       " & objAdapter.IPAddress(i)
 Next
 End If
 
 If Not IsNull(objAdapter.IPSubnet) Then
 For i = 0 To UBound(objAdapter.IPSubnet)
 MsgBox " Subnet:         " & objAdapter.IPSubnet(i)
 Next
 End If
 
 If Not IsNull(objAdapter.DefaultIPGateway) Then
 For i = 0 To UBound(objAdapter.DefaultIPGateway)
 MsgBox " Default gateway:    " & _
 objAdapter.DefaultIPGateway(i)
 Next
 End If
 
 
 MsgBox " DNS"
 MsgBox " ---"
 MsgBox "  DNS servers in search order:"
 
 If Not IsNull(objAdapter.DNSServerSearchOrder) Then
 For i = 0 To UBound(objAdapter.DNSServerSearchOrder)
 MsgBox "   " & objAdapter.DNSServerSearchOrder(i)
 Next
 End If
 
 MsgBox "  DNS domain: " & objAdapter.DNSDomain
 
 If Not IsNull(objAdapter.DNSDomainSuffixSearchOrder) Then
 For i = 0 To UBound(objAdapter.DNSDomainSuffixSearchOrder)
 MsgBox "  DNS suffix search list: " & _
 objAdapter.DNSDomainSuffixSearchOrder(i)
 Next
 End If
 MsgBox " DHCP"
 MsgBox " ----"
 MsgBox "  DHCP enabled:    " & objAdapter.DHCPEnabled
 MsgBox "  DHCP server:     " & objAdapter.DHCPServer
 
 If Not IsNull(objAdapter.DHCPLeaseObtained) Then
 utcLeaseObtained = objAdapter.DHCPLeaseObtained
 strLeaseObtained = WMIDateStringToDate(utcLeaseObtained)
 Else
 strLeaseObtained = ""
 End If
 MsgBox "  DHCP lease obtained: " & strLeaseObtained
 
 If Not IsNull(objAdapter.DHCPLeaseExpires) Then
 utcLeaseExpires = objAdapter.DHCPLeaseExpires
 strLeaseExpires = WMIDateStringToDate(utcLeaseExpires)
 Else
 strLeaseExpires = ""
 End If
 MsgBox "  DHCP lease expires: " & strLeaseExpires
 
 MsgBox " WINS"
 MsgBox " ----"
 MsgBox "  Primary WINS server:  " & objAdapter.WINSPrimaryServer
 MsgBox "  Secondary WINS server: " & objAdapter.WINSSecondaryServer
 
 n = n + 1
 
 Next
 End Sub
 
 すると、目的のIPアドレスやサブネットマスクが
 表示されました!
 
 あとは、事前に記録したIPアドレスなどを端末に
 設定するコードを書く作業がありますが、
 ありがとうございます。
 
 一応、WEB検索もしたのですが
 なかなか出てこなかったのは、
 
 エクセル IPアドレス 取得
 として、検索していたのが原因のようでした。
 
 |  |