I've updated the code to reference Excel; however now I am getting this error:
Runtime Error '3001":
Arguements are of the wrong type, are out of acceptable range or in conflict with eachother.
Here is the updated code:
Private Sub ExportBtn_Click()
Dim cnn As ADODB.Connection
Set cnn = CurrentProject.Connection
Dim MyRecordSet As New ADODB.Recordset
MyRecordSet.ActiveConnection = cnn
'Build the SQL Statement
Dim MySQL As String
MySQL = "SELECT [CondKey] , [AutoPop], [SalesOrg], [DistChannel], [CustomerID]"
MySQL = MySQL + "[KeyR], [PriceBreak_EffectDate],[UOM_EndDate], [Rate], [Currency_RateUnit]"
MySQL = MySQL + "[Per],[Keyx] , [KeyY], [HeaderUOM]"
MySQL = MySQL + "FROM tbl_Custom_Pricing_Template_Data_Flats"
MyRecordSet.Open MSQL
'template file as used to create SAP Excel Template File
Dim MySheetPath As String
'Set the path for the template file
MySheetPath = "C:\temp\zbp1template.xls"
' Set up object variables to refer to Excel and Objects
Dim Xl As Object
Dim Xlbook As Object
Dim Xlwks As Object
'Open an instance of Excel, open the workbook
Set Xl = CreateObject("Excel.Application")
Set ObjectVarName = GetObject(MySheetPath)
'Make Excel workbook visible on screen
Xl.Visible = True
Xlbook.Windows(1).Visible = True
'Define first sheet in workbook as Xlwks
Set Xlwks = Xlbook.Worksheets(1)
'Set Header Rows & Copy Data from Access Table "tbl_Custom_Pricing_Template_Data_Flats" to Excel Worksheet
Xlwks.Range("A1") = "BGR00"
Xlwks.Range("B1") = "0"
Xlwks.Range("C1") = "ZBP1907"
Xlwks.Range("D1") = "<SY-MANDT> OPTIONAL"
Xlwks.Range("E1") = "<SY-UNAME> OPTIONAL"
Xlwks.Range("A2") = "BKOND1"
Xlwks.Range("B2") = "1"
Xlwks.Range("C2") = "XK15"
Xlwks.Range("A3:X1500").Locked = False
'Save Workbook
Xlbook.Save
'Clean and set worksheet to screen
Set Xl = Nothing
Set Xlbook = Nothing
Set XlSheet = Nothing
End Sub