excel中添加日志如IP地址,这代码如何修改呢

榆木 2022-03-05 13:20:35

 

 

 

 

附上代码,前面已经可以获取IP值了,但是怎么修改才能实现我要的效果呢,请教老师们。


Dim XX
'获取IP地址
Sub GetMyIP()
Dim strComputer As String
Dim sb As String

Dim objWMI As Object
Dim colIP As Object
Dim IP As Object
Dim i As Integer

strComputer = "."
Set objWMI = GetObject("winmgmts://" & strComputer & "/root/cimv2")
Set colIP = objWMI.ExecQuery _
    ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each IP In colIP
    If Not IsNull(IP.IPAddress) Then
        For i = LBound(IP.IPAddress) To UBound(IP.IPAddress)
        MsgBox IP.IPAddress(i), vbInformation, IP.Description(i)
    Next
    End If
Next

End Sub





'修改单元格后,在sheet2中列出修改日志
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal target As Range)
On Error Resume Next
If Sh.Name <> "Sheet2" And target.Rows.Count = 1 Then
With Sheets("Sheet2")
If XX <> target Then
ROW1 = Sheets("Sheet2").[A65536].End(xlUp).Row + 1
.Cells(ROW1, 1) = Format(Now, "yyyy-mm-dd hh:mm:ss")
.Cells(ROW1, 2) = Sh.Name
.Cells(ROW1, 3) = XX
.Cells(ROW1, 4) = target.Value
.Cells(ROW1, 5) = target.Address(0, 0)
.Cells(ROW1, 6) = Environ("username")
.Cells(ROW1, 7) = IP.IPAddress


End If
End With
End If
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal target As Range)
XX = target.Value
End Sub

 

 

...全文
32 回复 打赏 收藏 举报
写回复
回复
切换为时间正序
请发表友善的回复…
发表回复
相关推荐
发帖
VBA
加入

2167

社区成员

VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
申请成为版主
帖子事件
创建了帖子
2022-03-05 13:20
社区公告
暂无公告