
FileSystemObjectのGetDriveNameメソッドについてです。
GetDriveNameメソッド
概要
指定したパスのドライブ名を返します。
構文
FileSystemObject.GetDriveName(path)
GetDriveNameメソッドの引数
引 数 | 必須 / 省略可 | 詳 細 |
パス | 必須 | パスを指定します。 |
VBAサンプル
ファイルの存在をFileExistsメソッドで確認してからドライブ名を取得。
1 2 3 4 5 6 7 8 9 10 11 | Sub test() Dim path As String: path = "D:\FSO\Folder1\test.xlsx" Dim fso As Object Set fso = CreateObject("Scripting.FileSystemObject") 'ファイルが存在したらドライブ名を取得 If fso.FileExists(path) Then Debug.Print fso.GetDriveName(path) End If End Sub |
【ファイル】
【結果】
D: