- 启用Excel开发工具
- 打开Excel 的VBA (ALT+F11)
- 新键VBA工程模块
- 写入自定义函数
Function HexIPAddr(strIPAddr As String, isAsc As Boolean) As String Dim arry, bit0 As String, bit1 As String, bit2 As String, bit3 As String arry = Split(strIPAddr, ".") bit0 = Hex(arry(0)) bit1 = Hex(arry(1)) bit2 = Hex(arry(2)) bit3 = Hex(arry(3)) If Len(bit0) = 1 Then bit0 = "0" + bit0 End If If Len(bit1) = 1 Then bit1 = "0" + bit1 End If If Len(bit2) = 1 Then bit2 = "0" + bit2 End If If Len(bit3) = 1 Then bit3 = "0" + bit3 End If If isAsc = True Then HexIPAddr = bit0 + bit1 + bit2 + bit3 Else HexIPAddr = bit3 + bit2 + bit1 + bit0 End If End Function
- 另存为 启用宏 的工作簿
-
重新打开即可使用刚刚创建的自定义函数
标签:VBA,End,String,自定义,Excel,bit3,bit2,bit1,bit0 From: https://www.cnblogs.com/jianxiaoxiu/p/17365286.html