1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| Sub Button1_Click()
Dim hexstring As String
hexstring = ActiveCell.Value
Dim charactersinstring
charactersinstring = Len(hexstring) / 2
Dim stringlength As Integer
stringlength = Len(hexstring)
Dim characters As String
Dim assembledcharacters As String
ReplacChrSpece (Chr(10) & Chr(13) & Chr(9) & "/" & "-" & ":")
For i = 1 To stringlength
characters = Mid(hexstring, i, 1)
characters = characters & Mid(hexstring, i + 1, 1)
i = i + 1
If characters <> "00" Then
assembledcharacters = assembledcharacters & Chr(Hex2Dec(characters)) 'fonction
End If
Next
ActiveCell.Value = assembledcharacters
End Sub
Function ReplacChrSpece(t As String) As String
ReplacChrSpece = t
ReplacChrSpece = Replace(ReplacChrSpece, Chr(10), "") 'Retour charriau
ReplacChrSpece = Replace(ReplacChrSpece, Chr(13), "") 'Fin de ligne
ReplacChrSpece = Replace(ReplacChrSpece, Chr(9), "") 'Tabulation
ReplacChrSpece = Replace(ReplacChrSpece, "/", "")
ReplacChrSpece = Replace(ReplacChrSpece, "-", "")
ReplacChrSpece = Replace(ReplacChrSpece, ":", "")
End Function
Function Hex2Dec(ByVal n1 As String) As Long
Dim nl1 As Long
Dim nGVal As Long
Dim nSteper As Long
Dim nCount As Long
Dim x As Long
Dim nVal As Long
Dim Stepit As Long
Dim hVal As String
nl1 = Len(n1)
nGVal = 0
nSteper = 16
nCount = 1
For x = nl1 To 1 Step -1
hVal = UCase(Mid$(n1, x, 1))
Select Case hVal
Case "A"
nVal = 10
Case "B"
nVal = 11
Case "C"
nVal = 12
Case "D"
nVal = 13
Case "E"
nVal = 14
Case "F"
nVal = 15
Case Else
nVal = Val(hVal)
End Select
Stepit = (nSteper ^ (nCount - 1))
nGVal = nGVal + nVal * Stepit
nCount = nCount + 1
Next x
Hex2Dec = nGVal
End Function |
Partager