Using the following code to import two separate worksheets from two different workbooks into the active workbook. The code does indeed import the data but there are some efficiencies needed.
Specifically, I would like to modify the code to accomplish;
1. Close any unnecessary objects.
Currently, the code results in two workbooks - Book1 and Book2 that remain open.
2. Import the active range of data from the two worksheets within the two different workbooks. Currently, I specify the range of data to copy - A1:O38827 - from each worksheet
3. Add a column at the right of the imported data that displays the date that I imported the data. Something along the lines of "DateImported" that will contain the date and time that I imported the data.
Currently attempting to code desired modifications but would appreciate any additional insight.
What modifications to the code will enable me to accomplish my objectives?
Specifically, I would like to modify the code to accomplish;
1. Close any unnecessary objects.
Currently, the code results in two workbooks - Book1 and Book2 that remain open.
2. Import the active range of data from the two worksheets within the two different workbooks. Currently, I specify the range of data to copy - A1:O38827 - from each worksheet
3. Add a column at the right of the imported data that displays the date that I imported the data. Something along the lines of "DateImported" that will contain the date and time that I imported the data.
Currently attempting to code desired modifications but would appreciate any additional insight.
What modifications to the code will enable me to accomplish my objectives?
Code:
Sub mcrImportCepAP_CurrMonthCurrYear()
'
' mcrImportCepAP_CurrMonthCurrYear Macro
Dim wb As Workbook
Dim activeWB As Workbook
Dim FilePath As String
Set activeWB = Application.ActiveWorkbook
FilePath = "C:\Test\CepAP_201309_Excel.xlsx"
Set wb = Application.Workbooks.Open(FilePath)
wb.Worksheets("Detail").Copy
Sheets("Detail").Select
Range("A1:O38827").Select 'Need to select active range
Selection.Copy
Windows("CashRev.xlsm").Activate
Sheets("CepAP_201309_Excel").Select
ActiveSheet.Paste
Windows("CepAP_201309_Excel.xlsx").Activate
ActiveWorkbook.Close
FilePath = "C:\Test\CepAP_201209_Excel.xlsx"
Set wb = Application.Workbooks.Open(FilePath)
wb.Worksheets("Detail").Copy
Sheets("Detail").Select
Range("A1:O38827").Select 'Need to select active range
Selection.Copy
Windows("CashRev.xlsm").Activate
Sheets("CepAP_201209_Excel").Select
ActiveSheet.Paste
Windows("CepAP_201209_Excel.xlsx").Activate
ActiveWorkbook.Close
'Columns("A:A").EntireColumn.AutoFit
'activeWB.Activate
'wb.Close False
End Sub