VBA ファイルの存在を確認 ファイルの存在を確認 Sub test() 'ファイルの存在を確認 '(VBEで[ツール]⇒ [参照設定]⇒ [Microsoft Scripting Runtime] をつける必要) Dim fso As FileSystemObject Set fso = New FileSystemObject ' インスタンス化 Dim myBoo As Boolean myBoo = fso.FileExists("D:\test\Test220426.txt") ' ファイルの存在確認 ' True なら存在する If myBoo = True Then MsgBox "ファイルが存在します。", vbInformation Else MsgBox "ファイルが存在しません。", 16 End If ' 後始末(初期化) Set fso = Nothing End Sub 実行結果 設定方法 ― ― ― ― ― ― ― ― ― ― → Excel VBA基礎入門もくじ へ戻る