VBScript

ファイル選択ダイアログ

ファイル選択ダイアログを表示するVBScriptをまとめてみました。
OSやIEのバージョンによっては実行できないものもあります。

Option Explicit

'MsgBox GetFilePathMC()
'MsgBox GetFilePathSF()
'MsgBox GetFilePathUACD()
'MsgBox GetFilePathIE()
MsgBox GetFilePathIE2()

Private Function GetFilePathMC()
'Comdlg32.ocxを利用したダイアログ
'※ 要コントロールデザイン時のライセンス(http://support.microsoft.com/kb/281848/ja)
  With CreateObject("MSComDlg.CommonDialog")
    .Filter = "All Files|*.*"
    .InitDir = "."
    .MaxFileSize = 256
    .ShowOpen
    GetFilePathMC = .FileName
  End With
End Function

Private Function GetFilePathSF()
'SAFRCFileDlg.FileOpenを利用したダイアログ
'※ Windows XP限定
  With CreateObject("SAFRCFileDlg.FileOpen")
    If .OpenFileOpenDlg Then GetFilePathSF = .FileName
  End With
End Function

Private Function GetFilePathUACD()
'UserAccounts.CommonDialogを利用したダイアログ
'※ Windows XP限定
  With CreateObject("UserAccounts.CommonDialog")
    .Filter = "All Files|*.*"
    .InitialDir = "."
    If .ShowOpen Then GetFilePathUACD = .FileName
  End With
End Function

Private Function GetFilePathIE()
'IEを利用したダイアログ
'※ Internet Explorer 8以降ではfakepathが返されます。
  Dim iptObj
  Dim ret
  
  With CreateObject("InternetExplorer.Application")
    .Visible = False
    .Navigate "about:blank"
    
    '表示待ち
    While .Busy Or .readyState <> 4
      WScript.Sleep 100
    Wend
    
    Set iptObj = .document.createElement("input")
    iptObj.setAttribute "type", "file"
    .document.body.appendChild iptObj
    iptObj.Click
    ret = iptObj.Value
    Set iptObj = Nothing
    .Quit
  End With
  GetFilePathIE = ret
End Function

Private Function GetFilePathIE2()
'IEを利用したダイアログ(2)
'※ Internet Explorer 8以降にも対応
  Dim iptObj
  Dim ret
  
  With CreateObject("InternetExplorer.Application")
    .Visible = False
    .FullScreen = True
    .Navigate "about:blank"
    
    '表示待ち
    While .Busy Or .readyState <> 4
      WScript.Sleep 100
    Wend
    
    Set iptObj = .document.createElement("input")
    iptObj.setAttribute "type", "file"
    .document.body.appendChild iptObj
    iptObj.Click
    If Trim(Len(iptObj.Value)) > 0 Then
      iptObj.Focus
      .ExecWB 17, 0 'OLECMDID_SELECTALL
      .ExecWB 12, 0 'OLECMDID_COPY
      ret = CreateObject("htmlfile").parentWindow.clipboardData.GetData("text")
    End If
    Set iptObj = Nothing
    .Quit
  End With
  GetFilePathIE2 = ret
End Function

クリップボードに文字列をコピーする前のページ

bitlyのAPIキーを取得する次のページ

関連記事

  1. Office関連

    KB2553154の更新プログラムをアンインストールするVBScript

    2014/12/11 追記:当記事で紹介しているのは更新プログラム…

  2. Windows関連

    ダウンロードフォルダーのパスを取得するVBScript

    ダウンロードフォルダーのパスを取得する必要があったので、過去に書いた記…

  3. VBScript

    Windows Updateの更新履歴をCSV(UTF-8)で保存するVBScript

    以前書いたスクリプトが出てきました。Windows Updateの…

  4. VBScript

    パスワードに使えそうなランダムな文字列を作成するVBScript

    前回の記事の続きです。前回はGUIDを作成するスクリプトでした…

  5. VBScript

    画像の一部にぼかしを入れるバッチ処理

    Paint.NETなどの画像処理ソフトを使うと、簡単に画像にぼかしを入…

  6. Windows関連

    特殊フォルダーのパスを取得するVBScript

    ファイルのコピーや移動を行う場合に特殊フォルダーのパスが必要になること…

コメント

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

  1. 2013年 12月 02日

Time limit is exhausted. Please reload CAPTCHA.

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

Translate

最近の記事

アーカイブ

PAGE TOP