Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 60761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:12:45+00:00 2026-05-10T18:12:45+00:00

Is there a built-in way to URL encode a string in Excel VBA or

  • 0

Is there a built-in way to URL encode a string in Excel VBA or do I need to hand roll this functionality?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T18:12:46+00:00Added an answer on May 10, 2026 at 6:12 pm

    No, nothing built-in (until Excel 2013 – see this answer).

    There are three versions of URLEncode() in this answer.

    • A function with UTF-8 support. You should probably use this one (or the alternative implementation by Tom) for compatibility with modern requirements.
    • For reference and educational purposes, two functions without UTF-8 support:
      • one found on a third party website, included as-is. (This was the first version of the answer)
      • one optimized version of that, written by me

    A variant that supports UTF-8 encoding and is based on ADODB.Stream (include a reference to a recent version of the ‘Microsoft ActiveX Data Objects’ library in your project):

    Public Function URLEncode( _    ByVal StringVal As String, _    Optional SpaceAsPlus As Boolean = False _ ) As String   Dim bytes() As Byte, b As Byte, i As Integer, space As String    If SpaceAsPlus Then space = '+' Else space = '%20'    If Len(StringVal) > 0 Then     With New ADODB.Stream       .Mode = adModeReadWrite       .Type = adTypeText       .Charset = 'UTF-8'       .Open       .WriteText StringVal       .Position = 0       .Type = adTypeBinary       .Position = 3 ' skip BOM       bytes = .Read     End With      ReDim result(UBound(bytes)) As String      For i = UBound(bytes) To 0 Step -1       b = bytes(i)       Select Case b         Case 97 To 122, 65 To 90, 48 To 57, 45, 46, 95, 126           result(i) = Chr(b)         Case 32           result(i) = space         Case 0 To 15           result(i) = '%0' & Hex(b)         Case Else           result(i) = '%' & Hex(b)       End Select     Next i      URLEncode = Join(result, '')   End If End Function 

    This function was found on freevbcode.com:

    Public Function URLEncode( _    StringToEncode As String, _    Optional UsePlusRatherThanHexForSpace As Boolean = False _ ) As String    Dim TempAns As String   Dim CurChr As Integer   CurChr = 1    Do Until CurChr - 1 = Len(StringToEncode)     Select Case Asc(Mid(StringToEncode, CurChr, 1))       Case 48 To 57, 65 To 90, 97 To 122         TempAns = TempAns & Mid(StringToEncode, CurChr, 1)       Case 32         If UsePlusRatherThanHexForSpace = True Then           TempAns = TempAns & '+'         Else           TempAns = TempAns & '%' & Hex(32)         End If       Case Else         TempAns = TempAns & '%' & _           Right('0' & Hex(Asc(Mid(StringToEncode, _           CurChr, 1))), 2)     End Select      CurChr = CurChr + 1   Loop    URLEncode = TempAns End Function 

    I’ve corrected a little bug that was in there.


    I would use more efficient (~2× as fast) version of the above:

    Public Function URLEncode( _    StringVal As String, _    Optional SpaceAsPlus As Boolean = False _ ) As String    Dim StringLen As Long: StringLen = Len(StringVal)    If StringLen > 0 Then     ReDim result(StringLen) As String     Dim i As Long, CharCode As Integer     Dim Char As String, Space As String      If SpaceAsPlus Then Space = '+' Else Space = '%20'      For i = 1 To StringLen       Char = Mid$(StringVal, i, 1)       CharCode = Asc(Char)       Select Case CharCode         Case 97 To 122, 65 To 90, 48 To 57, 45, 46, 95, 126           result(i) = Char         Case 32           result(i) = Space         Case 0 To 15           result(i) = '%0' & Hex(CharCode)         Case Else           result(i) = '%' & Hex(CharCode)       End Select     Next i     URLEncode = Join(result, '')   End If End Function 

    Note that neither of these two functions support UTF-8 encoding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 75k
  • Answers 75k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I'm confused as to what exactly the problem is. Why… May 11, 2026 at 2:39 pm
  • added an answer The following code in a servlet filter has worked for… May 11, 2026 at 2:39 pm
  • added an answer Use the PHP filter functions. You can use them for… May 11, 2026 at 2:39 pm

Related Questions

I've been tasked with creating a tool that can diff and merge the configuration
I've got a string in .NET which is actually a URL. I want an
I run a browser based game at www.darknovagames.com. Recently, I've been working on reformatting
I have a form I am submitting via AJAX (using prototype and the built-in

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.