contact@exceltr.com

ExcelTR - Microsoft Excel Eğitim Sitesi

Görsel Video Microsoft Excel Eğitim Sitesi
29 Şub 2012

VBA UTF-8 URL Encode

//
Yorumlar0
/
Etiketler, , ,

Excelde VBA kullanarak bazi verilerinizi sifelemek yani encode etmek isteyebilirsiniz, bunu yapabileceginiz bir utf-8 sofreleyici bir kod paylasiyoruz.

Public Function uriEncode(ByVal str As String)

    Dim i As Integer
    Dim iAsc As Long
    Dim sAsc As String
    Dim sTemp As String

    Dim objStream As Object
    Dim data() As Byte
    Dim ByteArrayToEncode() As Byte


    Set objStream = CreateObject("ADODB.Stream")
    objStream.Charset = "utf-8"
    objStream.Mode = 3
    objStream.Type = 2
    objStream.Open
    objStream.WriteText str
    objStream.flush
    objStream.Position = 0
    objStream.Type = 1
    objStream.Read 3
    data = objStream.Read()
    objStream.Close
    ByteArrayToEncode = data

    str = ""

    For i = 0 To UBound(ByteArrayToEncode)
        iAsc = ByteArrayToEncode(i)
        Select Case iAsc
            Case 32    'space
                sTemp = "+"
            Case 48 To 57, 65 To 90, 97 To 122
                sTemp = Chr(ByteArrayToEncode(i))
            Case Else
                '  Debug.Print iAsc
                sTemp = "%" & Hex(iAsc)
        End Select
        str = str & sTemp
    Next

    uriEncode = str

End Function

 

Cevap bırakın


7 + 1 =