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. Windows関連

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

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

  2. Windows関連

    Windows 8を従来のスタイルに変更するスクリプト

    2012/3/2 追記:下記情報はWindows Develope…

  3. VBScript

    指定したフォルダ内のemlファイルの情報をリスト化するVBScript

    emlファイルから件名や本文、宛先や送信日時といった各種情報を取得して…

  4. Office関連

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

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

  5. Excel

    ヘッドレス ChromeとSeleniumBasicでWebページ全体のスクリーンショットを撮る方法…

    先日、ヘッドレス ChromeでWebページ全体のスクリーンショットを…

コメント

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

  1. 2013年 12月 02日

Time limit is exhausted. Please reload CAPTCHA.

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

Translate

最近の記事

アーカイブ

PAGE TOP