Office関連

64ビット版OfficeでURLエンコード処理ができない?

2011/12/28 追記:
関連記事として「文字コードを指定してURLエンコードを行う」を書きました。

64ビット環境でのScriptControlの代わり」で記事を書いていますが、64ビット環境でScriptControlを利用してURLエンコード処理を行おうとした場合、エラーが発生して処理することができません(64ビットOS上の32ビット版Office(WOW64上)ではエラーになりません)。

これは「msscript.ocx」が64ビット環境に対応していないためですが、今回は「64ビット環境でのScriptControlの代わり」で紹介している方法とは違う方法でURLエンコード処理を実行してみます。

[標準モジュール]

Option Explicit

Public Sub Sample()
  MsgBox EncodeURLx64("東京都千代田区")
End Sub

Public Function EncodeURLx64(ByVal str As String) As String
  Dim s As String, com As String, ret As String
  Dim ScriptFilePath As String, ExeFilePath As String
  
  ret = "" '初期化
  
  'スクリプト用コード設定
  s = "Option Explicit" & vbCrLf
  s = s & vbCrLf
  s = s & "Dim Args, ret" & vbCrLf
  s = s & vbCrLf
  s = s & "Set Args = WScript.Arguments" & vbCrLf
  s = s & "If Args.Count < 1 Then WScript.Quit" & vbCrLf
  s = s & "With CreateObject(""ScriptControl"")" & vbCrLf
  s = s & "  .Language = ""JScript""" & vbCrLf
  s = s & "  ret = .CodeObject.encodeURIComponent(Args(0))" & vbCrLf
  s = s & "End With" & vbCrLf
  s = s & "Set Args = Nothing" & vbCrLf
  s = s & "WScript.Echo ret"
  
  ScriptFilePath = VBA.Environ$("TEMP") & "\enc.vbs"
  With CreateObject("Scripting.FileSystemObject")
    With .CreateTextFile(ScriptFilePath, True)
      .Write s
      .Close
    End With
    If .FileExists(ScriptFilePath) Then
      ExeFilePath = .GetSpecialFolder(0).Path & "\SysWOW64\cscript.exe"
      If .FileExists(ExeFilePath) Then
        com = ExeFilePath & " //Nologo """ & ScriptFilePath & """ """ & str & """"
        ret = CreateObject("WScript.Shell").Exec(com).StdOut.ReadAll
      End If
      .DeleteFile ScriptFilePath
    End If
  End With
  EncodeURLx64 = ret
End Function

上記「Sample」を実行すると、MsgBoxでURLエンコード処理された文字列が表示されます。

上記コードでは一時的にVBScriptファイルを作成し、32ビット版のcscript.exeでそのスクリプトを実行することで、URLエンコード処理を行っています。

menu内にあるbuttonの数を増やす前のページ

McAf.eeで短縮URLを取得するブックマークレット次のページ

関連記事

  1. Office関連

    Office製品の開発者用リファレンス(ダウンロード版)

    Docs.comでまとめていたリンクなんですが、来月15日にすべて廃止…

  2. Windows 10

    SeleniumBasic(Selenium VBA)がMicrosoft Edgeに対応しました。…

    言わずと知れたWebブラウザーの自動制御ツール「Selenium」のV…

  3. アイコン一覧

    Office 2013 アイコン一覧(Q)

    ・Office 2013 アイコン一覧 NUM…

  4. Office アドイン

    [Officeアドイン]アドイン コマンド(Add-In Commands)の紹介(2)

    昨年末に書いた記事で「アドイン コマンド」を紹介しているのですが、知ら…

  5. アイコン一覧

    Office 2013 アイコン一覧(E)

    ・Office 2013 アイコン一覧 NUM…

  6. アイコン一覧

    Office 365アイコン(imageMso)一覧(T)

    Office 365のデスクトップ版Officeアプリケーション(Wo…

コメント

  1. この記事へのコメントはありません。

Time limit is exhausted. Please reload CAPTCHA.

※本ページはプロモーションが含まれています。

Translate

最近の記事

アーカイブ

PAGE TOP