I have an "import" macro I've been using that is suppose to copy all the sheets in workbook and move them to another workbook. Instead, it copie the first worksheet multiple times and then moves into the workbook.
Sub ImportDriverTripReport()
Dim ImportItemCount, RowCount As Integer
Dim DCSwb, ImportWb As Workbook
Dim ImportDate As Integer
Dim FileLocation As String
Dim x As Integer
Application.StatusBar = "Please Select the file to Import..."
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlManual
'Import the driver trip report sheet
FileLocation = Application.GetOpenFilename("Excel Files (*.xls), *.xls")
'::: IMPORT THE DATA INTO THE TEMPLATE :::
Set DCSwb = ActiveWorkbook
Application.StatusBar = "Importing File..."
'Opens the file the user specified
Workbooks.Open Filename:=FileLocation
Set ImportWb = ActiveWorkbook
For x = 1 To ActiveWorkbook.Sheets.Count
'Loop through each of the sheets in the workbook by using x as the sheet index number.
ActiveWorkbook.Sheets(x).Copy _
After:=DCSwb.Sheets("Control Panel")
'Puts all copies after the last existing sheet.
Application.StatusBar = Null
Next
End Sub
I can't figure out why its copying the same worksheet multiple times, but I'm assuming it has something to do with the loop coding, which I'm not very good with. Any idea? Thanks!
Sub ImportDriverTripReport()
Dim ImportItemCount, RowCount As Integer
Dim DCSwb, ImportWb As Workbook
Dim ImportDate As Integer
Dim FileLocation As String
Dim x As Integer
Application.StatusBar = "Please Select the file to Import..."
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlManual
'Import the driver trip report sheet
FileLocation = Application.GetOpenFilename("Excel Files (*.xls), *.xls")
'::: IMPORT THE DATA INTO THE TEMPLATE :::
Set DCSwb = ActiveWorkbook
Application.StatusBar = "Importing File..."
'Opens the file the user specified
Workbooks.Open Filename:=FileLocation
Set ImportWb = ActiveWorkbook
For x = 1 To ActiveWorkbook.Sheets.Count
'Loop through each of the sheets in the workbook by using x as the sheet index number.
ActiveWorkbook.Sheets(x).Copy _
After:=DCSwb.Sheets("Control Panel")
'Puts all copies after the last existing sheet.
Application.StatusBar = Null
Next
End Sub
I can't figure out why its copying the same worksheet multiple times, but I'm assuming it has something to do with the loop coding, which I'm not very good with. Any idea? Thanks!