با استفاده از تابع ذیل می توان بررسی نمود که فایل در مسیر مورد نظر وجود دارد یا خیر
Option Explicit
Sub DoesFileExist()    
    Const FileName As String = "E:\WEBiNUX_Control.bin"
    Dim FolderPath As String
    FolderPath = ThisWorkbook.Path
    Dim FilePath As String
    'FilePath = FolderPath & Application.PathSeparator & FileName
    FilePath = FileName
    
    If Not FileExists(FilePath) Then
        Application.ScreenUpdating = False
        With Workbooks.Add
            ' You might wanna improve here e.g. add title, headers ...
            .SaveAs FileName:=FilePath, _
                    FileFormat:=xlOpenXMLWorkbookMacroEnabled
            .Close SaveChanges:=False
        End With
        Application.ScreenUpdating = True
        MsgBox "Master workbook created!", vbInformation
    Else
        MsgBox "Master workbook already exists!", vbExclamation
    End If
End Sub
Function FileExists(ByVal FilePath As String) _
         As Boolean
    With CreateObject("Scripting.FileSystemObject")
        If .FileExists(FilePath) Then
            FileExists = True
        End If
    End With
End Function
خروجی تابع بصورت True یا False بازگردانده میشود

ورود به سایت