Hello,
Below code helps me to open closed Sheet and copy the particular sheet into opened sheet. But when sheet is not found, VBA still runs to next macro which built right below. I need help in closing the VBA running right below in Red line.
Please advice![]()
Dim sImportFile As String, sFile As String Dim sThisBk As Workbook Dim vfilename As Variant Application.ScreenUpdating = False Application.DisplayAlerts = False Set sThisBk = ActiveWorkbook sImportFile = Application.GetOpenFilename( _ fileFilter:="Microsoft Excel Workbooks, *.xls; *.xml; *.xlsx", Title:="Open Workbook") If sImportFile = "False" Then MsgBox "No File Selected!" Exit Sub Else vfilename = Split(sImportFile, "\") sFile = vfilename(UBound(vfilename)) Application.Workbooks.Open Filename:=sImportFile Set wbBk = Workbooks(sFile) With wbBk If SheetExists("Worker") Then Set wsSht = .Sheets("Worker") wsSht.Copy After:=sThisBk.Sheets("Master File") Else MsgBox "There is no sheet with name :Raw_Data in:" & vbCr & .Name ' I need stop code here, which Stops the VBA and return to Userform1 Display. End If wbBk.Close savechanges:=False End With End If Application.ScreenUpdating = True Application.DisplayAlerts = True
Thanks
Bookmarks