FileSystemObject Runtimeにチェックを入れてオッケー。
サンプルソース
Sub start()
Dim file As Scripting.FileSystemObject
Dim filename As String
filename = “C:\Users\user\Desktop\it.xls”
Set file = New Scripting.FileSystemObject
With file
Range(“A1”).Value = .GetParentFolderName(filename)
Range(“A2”).Value = .GetFileName(filename)
End With
Dim file As Scripting.FileSystemObject
Dim filename As String
filename = “C:\Users\user\Desktop\it.xls”
Set file = New Scripting.FileSystemObject
With file
Range(“A1”).Value = .GetParentFolderName(filename)
Range(“A2”).Value = .GetFileName(filename)
End With
End Sub
実行結果
C:\Users\user\Desktop
it.xls
C:\Users\user\Desktop
it.xls
GetParentFolderNameはファイルパスを取得している。
GetFileNameはフェイル名を取得している。
ファイルやフォルダがあるか調べる
サンプルソース
Sub start()
Dim file As New Scripting.FileSystemObject
Dim filename As String
Dim Folder As String
Dim file As New Scripting.FileSystemObject
Dim filename As String
Dim Folder As String
With file
filename = “C:\Users\user\Desktop\it.xls”
Folder = “C:\Users\user\Desktop”
Range(“A1”).Value = .FileExists(filename)
Range(“A2”).Value = .FolderExists(Folder)
End With
End Sub
ファイルがあるか調べる
FileExists
フォルダがあるか調べる
FolderExists
ファイルの属性を調べる
サンプルソース
Sub start()
Dim file As New Scripting.FileSystemObject
Dim Sfile As Scripting.file
Dim filename As Variant
Dim file As New Scripting.FileSystemObject
Dim Sfile As Scripting.file
Dim filename As Variant
filename = Application.GetOpenFilename()
If filename = False Then Exit Sub
Set Sfile = file.GetFile(filename)
Range(“A1”).Value = Sfile.DateCreated
Range(“A2”).Value = Sfile.DateLastModified
Range(“A3”).Value = Sfile.Name
Range(“A4”).Value = Sfile.Path
End Sub
GetFile | ファイルオブジェクトを作成している |
DateCreated | ファイルの作成日を取得 |
DateLastModified | ファイルの更新日を取得 |
Name | ファイル名を取得 |
Path | ファイルパスを取得 |