6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

UrlエンコードをするVBAマクロ

Posted at


Option Explicit

'#-----------------------------------------
'# 文字列をURLエンコード
'#-----------------------------------------

Public Function encodeUrlUtf8(ByRef strSource As String) As String
    Dim objSC As Object
    
    Set objSC = CreateObject("ScriptControl")
    objSC.Language = "Jscript"
    encodeUrlUtf8 = objSC.CodeObject.encodeURIComponent(strSource)
    Set objSC = Nothing
    
End Function

'#-----------------------------------------
'# セルの値をURLエンコード
'#-----------------------------------------
Function encodeCellUrl(targetCell As Range) As String

    encodeCellUrl = encodeUrlUtf8(targetCell.value)
   
End Function

'#-----------------------------------------
'# URLエンコードメイン処理
'#-----------------------------------------
Sub encodeUrlMain()

    Dim targetRange As Range
    Dim targetCell As Range
    
    Set targetRange = Range("C3:C21")
    
    For Each targetCell In targetRange
        targetCell.Offset(0, 1).value = encodeCellUrl(targetCell)
    Next
    
End Sub

6
7
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?