teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

加筆修正

2016/09/07 09:39

投稿

退会済みユーザー
answer CHANGED
@@ -1,3 +1,35 @@
1
1
  FileSystemObjectをご存知でしょうか。
2
- [GetFile メソッド](https://msdn.microsoft.com/ja-jp/library/cc428018.aspx "GetFile メソッド")を駆使すれば、GetFileメソッドで得られたFileオブジェクトfに対して、
2
+ [GetFile メソッド](https://msdn.microsoft.com/ja-jp/library/cc428018.aspx)を駆使すれば、GetFileメソッドで得られたFileオブジェクトfに対して、
3
- f.Sizeでファイルサイズが、f.DateLastModifiedで最終更新日時を取得できます。
3
+ f.Sizeでファイルサイズが、f.DateLastModifiedで最終更新日時を取得できます。
4
+
5
+ VBEでFileSystemObjectの参照設定を行う:FileSystemObjectの使い方
6
+ [http://www.relief.jp/itnote/archives/fso-vba-references.php](http://www.relief.jp/itnote/archives/fso-vba-references.php)
7
+
8
+ VBAに参照設定を追加すれば、FileSystemObjectが使えます。
9
+ ざっくり書くとこうなるでしょうか。
10
+
11
+ ```
12
+ Sub test()
13
+ Dim fso As Scripting.FileSystemObject
14
+ Dim f As Scripting.File
15
+
16
+ Set fso = New Scripting.FileSystemObject
17
+ If fso Is Nothing Then
18
+ MsgBox "FileSystemObjectが使えない", vbCritical
19
+ Exit Sub
20
+ End If
21
+
22
+ Set f = fso.GetFile("C:\xxxx.xls")
23
+ If f Is Nothing Then
24
+ MsgBox "ファイルが見つからない", vbCritical
25
+ Exit Sub
26
+ End If
27
+
28
+ Debug.Print f.Size '' ファイルサイズ
29
+ Debug.Print f.DateLastModified '' 最終更新日時
30
+
31
+ Set f = Nothing
32
+ Set fso = Nothing
33
+ End Sub
34
+
35
+ ```