给你个例子:
Public Function Dec2Hex(ByVal x As String) As String
Dim dec, Temp, remain As Double
If Len(x) > 10 Then
MsgBox "输入的数字超过上限", vbExclamation
Exit Function
End If
dec = Val(x)
If dec > 4294967295# Then
MsgBox "输入的数字超过上限", vbExclamation
Exit Function
End If
Do
remain = Int(dec / 16)
Temp = remain * 16
Dec2Hex = Hex(dec - Temp) & Dec2Hex
dec = remain
Loop While dec
If Len(Dec2Hex) Mod 2 Then
Dec2Hex = "0" & Dec2Hex
End If
End Function