Hi All
Can someone please explain why this code isn't exporting the specified query to excel?
Option Compare Database
Option Explicit
Private Sub ExportCrossTabQuery()
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Set xlApp = New Excel.Application
With xlApp
.Visible = True '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''REMINDER: CHANGE THIS TO FALSE WHEN CODING COMPLETE
Set xlWB = .Workbooks.Open("C:\Database Exports\UPM.xlsx", , False)
.Sheets("qry_3213_ALL_Crosstab").Cells.ClearContents ''''''''''''''''''''''''''''''''''''FORMATTING MAINTAINED, ONLY CONTENTS ARE CLEARED
End With
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "qry_3213_ALL_Crosstab", "C:\Database Exports\UPM.xlsx" '''''EXPORT TO SPECIFIED EXCEL FILE
End Sub
Everything works as it should up until the End With statement, then it returns a run-time error 3010. I've confirmed that file locations, file/query names are correct but I'm also very new to the world of VBA so am probably missing something very simple. Would appreciate any assistance with this matter and would like to hear peoples tips for best practices when it comes to using VBA.
Thanks in advance.
Bookmarks