Hey everyone, I am having an issue when exporting a table from Access to Excel. I do not know why I keep getting an error, as I have used this code before. I'm assuming it's an easy fix and I'm just brain dead at this point of the day. Here's the code:
I get the Run-time error '13' on the following line ({Edit} Line #24):
Any help would be greatly appreciated!
Thanks
Code:
Private Sub Staffing_Click()
Dim dbs As DAO.Database
Dim objrst As DAO.Recordset
Dim strXLStaffing As String
Dim strStaff As String
Dim xlApp As Object
Dim xlWorkbook As Object
Dim xlSheet As Object
strXLStaffing = "C:\Lynch\Staffing.xlsx"
strStaff = "Daily Staffing List"
Set dbs = CurrentDb
Set objrst = Application.CurrentDb.OpenRecordset(strStaff)
Set xlApp = CreateObject("Excel.Application")
With xlApp
.Visible = False
.DisplayAlerts = False
Set xlWorkbook = Workbooks.Open(strXLStaffing)
Set xlSheet = xlWorkbook.Worksheets("Sheet2")
xlSheet.Activate
xlSheet.Range("A1").CopyFromRecordset strStaff
End With
With xlApp
.Save
.Quit
End With
Set objrst = Nothing
End Sub
Code:
xlSheet.Range("A1").CopyFromRecordset strStaff
Thanks
Comment