回答編集履歴
1
加筆修正
test
CHANGED
@@ -1,5 +1,69 @@
|
|
1
1
|
FileSystemObjectをご存知でしょうか。
|
2
2
|
|
3
|
-
[GetFile メソッド](https://msdn.microsoft.com/ja-jp/library/cc428018.aspx
|
3
|
+
[GetFile メソッド](https://msdn.microsoft.com/ja-jp/library/cc428018.aspx)を駆使すれば、GetFileメソッドで得られたFileオブジェクトfに対して、
|
4
4
|
|
5
5
|
f.Sizeでファイルサイズが、f.DateLastModifiedで最終更新日時を取得できます。
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
VBEでFileSystemObjectの参照設定を行う:FileSystemObjectの使い方
|
10
|
+
|
11
|
+
[http://www.relief.jp/itnote/archives/fso-vba-references.php](http://www.relief.jp/itnote/archives/fso-vba-references.php)
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
VBAに参照設定を追加すれば、FileSystemObjectが使えます。
|
16
|
+
|
17
|
+
ざっくり書くとこうなるでしょうか。
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
```
|
22
|
+
|
23
|
+
Sub test()
|
24
|
+
|
25
|
+
Dim fso As Scripting.FileSystemObject
|
26
|
+
|
27
|
+
Dim f As Scripting.File
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
Set fso = New Scripting.FileSystemObject
|
32
|
+
|
33
|
+
If fso Is Nothing Then
|
34
|
+
|
35
|
+
MsgBox "FileSystemObjectが使えない", vbCritical
|
36
|
+
|
37
|
+
Exit Sub
|
38
|
+
|
39
|
+
End If
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
Set f = fso.GetFile("C:\xxxx.xls")
|
44
|
+
|
45
|
+
If f Is Nothing Then
|
46
|
+
|
47
|
+
MsgBox "ファイルが見つからない", vbCritical
|
48
|
+
|
49
|
+
Exit Sub
|
50
|
+
|
51
|
+
End If
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
Debug.Print f.Size '' ファイルサイズ
|
56
|
+
|
57
|
+
Debug.Print f.DateLastModified '' 最終更新日時
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
Set f = Nothing
|
62
|
+
|
63
|
+
Set fso = Nothing
|
64
|
+
|
65
|
+
End Sub
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
```
|