sambrierley
Registered User.
- Local time
- Today, 08:34
- Joined
- Apr 24, 2014
- Messages
- 56
Hi all,
the below code exports a table (via a function) to a spreadsheet and saves it in a defined location. the code then opens the file does some work with it then moves it(left the move bit out as it works fine)
so when i run the code it works absolutle fine, table is exported, work is done and file is moved. however if i run the code again it fails, i get the error message out of range. i was originally getting this error when using the .usedrange.copy so i commented this out and now i get it on the next line that tries to work with the file so obviously something is wrong in my logic. can anyone see what it is?
thanks
the below code exports a table (via a function) to a spreadsheet and saves it in a defined location. the code then opens the file does some work with it then moves it(left the move bit out as it works fine)
so when i run the code it works absolutle fine, table is exported, work is done and file is moved. however if i run the code again it fails, i get the error message out of range. i was originally getting this error when using the .usedrange.copy so i commented this out and now i get it on the next line that tries to work with the file so obviously something is wrong in my logic. can anyone see what it is?
thanks
Code:
Private Sub Export2JDE_Click()
Application.Run ("JDE_Export") 'Exports to an xlsx file in the location described in the function.
Dim xlApp As excel.Application
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlApp.Workbooks.Open "T:\Inter Urban\Consultancy Services\Timesheets\Templates\Access\JDE.xlsx", True, False ' opens the recently exported file.
Set xlApp = Nothing
'Workbooks("JDE.xlsx").Sheets("TempHours").UsedRange.Copy 'copies all data,inc headings!!!!!
Dim Batch As Integer 'Batch number taken from JDE
Batch = InputBox("Your Export has been successfull. copy the Data into JDE and put the batch number in the box provided")
'DoCmd.RunSQL "INSERT INTO Archive SELECT * FROM TempHours"
Workbooks("JDE.xlsx").Sheets("TempHours").Cells(1, 18).Value = "Batch" 'inserts Batch as the heading
Workbooks("JDE.xlsx").Sheets("TempHours").Range(Cells(2, 18), Cells(Cells(Rows.Count, 1).End(xlUp).Row, 18)).Value = Batch 'inserts batch number into the xlsx file
ActiveWorkbook.Save
excel.Application.Quit
Dim MyFile As String
Dim MyPath As String
MyPath = "T:\Inter Urban\Consultancy Services\Timesheets\Templates\Access\JDE.xlsx"
'imports the JDE export into the archive with the batch number.
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Archive", _
MyPath, True, "TempHours!A:R"