In one of my code if I get an error i need to pop the file name with error and then resume next.Below is the code snippet i am trying to use but it is giving me error. Can anyone help me
sourcefilename = File_list.Cells(i + 1, 1)
    Set Baccha_Wbk = Wbk.Workbooks.Open(sourcefilename)
    On Error GoTo ErrMsg
ErrMsg:    MsgBox ("Error in file" & sourcefilename ),On Error Resume Next
                Another way to do it...
Sub Sample()
    Dim sFile As String
    '~~> If you are doing this in Excel. then you don't need Wbk
    Dim Wbk As Excel.Application
    Dim Baccha_Wbk As Workbook
    Dim i As Long
    On Error GoTo Whoa
    '
    '~~> Rest of the Code
    '
    sFile = File_list.Cells(i + 1, 1)
    If FileFolderExists(sFile) Then
        '~~> If you are doing this in Excel. then you don't need Wbk
        Set Baccha_Wbk = Wbk.Workbooks.Open(sFile)
    Else
        MsgBox "File Doesn't exists"
    End If
    Exit Sub
Whoa:
    MsgBox Err.Description
End Sub
Public Function FileFolderExists(strFullPath As String) As Boolean
    On Error GoTo EarlyExit
    If Not Dir(strFullPath, vbDirectory) = vbNullString Then FileFolderExists = True
EarlyExit:
    On Error GoTo 0
End Function
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With