Converting String to Hex in Excel VBA

后端 未结 2 1293
鱼传尺愫
鱼传尺愫 2021-01-05 17:34

I need to convert strings to hexadecimals in my Excel VBA macro.

I tried:

Dim val As String
val = \"10\"
Dim hexVal As Integer
hexVal = Convert.ToInt         


        
2条回答
  •  误落风尘
    2021-01-05 18:14

    In VBA you need to mess about with the &H literal:

    value = val("&H" & "10") '// 16
    value = val("&H3366CC")  '// 3368652
    

    Edit

    Function FromHex(hexString As String) As Long
        FromHex = Val("&H" & hexString)
    End Function
    

    Then

    resultString = hex$(FromHex("3366CC") / FromHex("A"))
    

    Or for constants obviously;

    resultString = hex$(FromHex("3366CC") / &HA)
    

提交回复
热议问题