VBAでダウンロードフォルダのパスを出力する

Last Updated on 2025年7月16日

行いたいこと

Excel VBA を使用して
Windows PC 内のダウンロードフォルダまでの
パスをイミディエイトウィンドウに出力させる。

コード
Sub GetDownloadsFolderPath()
Dim shell As Object
Dim downloadsPath As String

Set shell = CreateObject("WScript.Shell")
downloadsPath = shell.SpecialFolders("MyDocuments") & "\Downloads"

' イミディエイトウィンドウにパスを出力
Debug.Print "ダウンロードフォルダのパスは:" & downloadsPath
End Sub

実行結果

・ダウンロードフォルダのパスは:
C:\Users\xxx\Documents\Downloads