Hello Everyone,
I have question about checking specific sheets names in opened workbook before copying them to the correct workbook and if one of them does not exist then exit sub.
Currently I have this code:
I have question about checking specific sheets names in opened workbook before copying them to the correct workbook and if one of them does not exist then exit sub.
Currently I have this code:
Code:
Sub test()
Dim Wb1 As Workbook
Dim Wb2 As Workbook
Dim workbookpath As String
MsgBox "Please choose the file.'", vbInformation, "Information"
Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = False
Application.FileDialog(msoFileDialogOpen).Show
workbookpath = Application.FileDialog(msoFileDialogOpen).SelectedItems(1)
Cells(1, 1) = workbookpath
Set Wb1 = ActiveWorkbook
Set Wb2 = Workbooks.Open(workbookpath)
Wb2.Sheets("a").Copy after:=Wb1.Sheets("Start")
Wb2.Sheets("b").Copy after:=Wb1.Sheets("Start")
Wb2.Sheets("c").Copy after:=Wb1.Sheets("Start")
Wb2.Sheets("d").Copy after:=Wb1.Sheets("Start")
Wb2.Sheets("e").Copy after:=Wb1.Sheets("Start")
Wb2.Sheets("f").Copy after:=Wb1.Sheets("Start")
Wb2.Sheets("g").Copy after:=Wb1.Sheets("Start")
Wb2.Close
End Sub