I'm new at VBA so bear with me. I'm trying to copy worksheets from a specified file location into a master consolidated workbook. I would like to prevent copying duplicate worksheets into the consolidated workbook. For example, if sheet 1 has been copied into the Master consolidated workbook, I don't want to recopy it when the command has been ran. Below is the code I have so far.
Private Sub CommandButton1_Click()
Dim directory As String
Dim fileName As String
Dim sheet As Worksheet
Dim total As Integer
Application.ScreenUpdating = False
Application.DisplayAlerts = False
directory = "c:\test\"
' edit directory
fileName = Dir(directory & "*.xl??")
Do While fileName <> ""
Workbooks.Open (directory & fileName)
For Each sheet In Workbooks(fileName).Worksheets
total = Workbooks("test import.xlsm").Worksheets.Count
Workbooks(fileName).Worksheets(sheet.Name).Copy _
after:=Workbooks("test import.xlsm").Worksheets(total)
Next sheet
Workbooks(fileName).Close
fileName = Dir()
Loop
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub