All
I need to run this routine without adding the reference to use of Excel 12.0. This will be running on machines with Office 2007 as well as Office 2003 (Access2007Runtime)
The routine throws a Compile Error: User-defined type not defined at "Dim objXLBook As Excel.Workbook"
Any ideas on how to modify this code?
I need to run this routine without adding the reference to use of Excel 12.0. This will be running on machines with Office 2007 as well as Office 2003 (Access2007Runtime)
The routine throws a Compile Error: User-defined type not defined at "Dim objXLBook As Excel.Workbook"
Any ideas on how to modify this code?
Code:
Private Sub btnOutToExec_Click()
On Error GoTo ExecHandleError
Dim objXLApp As Object
Set objXLApp = CreateObject("Excel.Application")
Dim objXLBook As Excel.Workbook
Dim db As DAO.Database
Set db = CurrentDb
conPath = GetPath(db.Name)
'delete the spreadsheet
Kill conPath & "MySpreadsheet.xls"
' create a workbook from the template
Set objXLApp = New Excel.Application
Set objXLBook = objXLApp.Workbooks.Open(conPath & "GL Executive and Operational TEMPLATE.xlt")
'objXLApp.Visible = True
objXLBook.SaveAs (conPath & "GLT Executive and Operational Report.xls")
objXLBook.Close
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "ExecReportData", conPath & "GL Executive and Operational Report.xls", True
MsgBox "Done!" & vbCrLf & vbCrLf & "Look in the directory" & vbCrLf & vbCrLf & "where the application sits for ""GL Executive and Operational Report.xls"""
ProcDone:
On Error Resume Next
' Let's clean up our act
Set qdf = Nothing
Set db = Nothing
Set rs = Nothing
Set objResultsSheet = Nothing
Set objXLBook = Nothing
Set objXLApp = Nothing
ExitHere:
Exit Sub
ExecHandleError:
Select Case Err.Number
Case 3265
Resume Next
Case 1004
Set objXLBook = objXLApp.Workbooks.Open(conPath & "Generic1.xlt")
Resume Next
Case 53
Resume Next
Case 75
Resume Next
Case Else
MsgBox Err.Description, vbExclamation, _
"Error " & Err.Number
End Select
Resume ProcDone
End Sub