

Excelから特定のフォルダを開きたい――そんなときに使えるのが、WScript.ShellとそのRunメソッドです。
この記事では、VBAで「指定したフォルダをエクスプローラーで開く」方法をご紹介します
■ 参照設定なしで使える!
CreateObjectでWScript.Shellを呼び出す
Dim wsh As Object
Set wsh = CreateObject("WScript.Shell")
■ 参照設定ありで使える!
WScript.Shellを呼び出す
参照設定 → 「Windows Script Host Object Model」 を追加します。

Dim wsh As WshShell
Set wsh = New WshShell

例:エクスプローラーで「C:¥Windows」を開く
' 任意のパスに変更してください
Dim folderPath As String
folderPath = "C:\Windows"
' フォルダを開く
wsh.Run folderPath





コメントを残す