I am getting the error in the subject line when I execute the following function. I marked the line the debugger is stopping on.
This function runs fine on every computer in my office except my boss's laptop. He is running the same version and build of Windows and MS Office (Win2k and MSOffice2kPro) as everyone else. His computer has all the same references in the VBA IDE. I can't figure out what is causing the error. Any ideas.
Code:
Public Sub ExportToExcel(rptType As Integer, _
JobID As String, _
startdate As String, _
enddate As String)
On Error Resume Next 'Turn off error handling.
Dim objXL As Excel.Application
Dim objWKB As Excel.Workbook
Dim objSHT As Excel.Worksheet
Dim rs As ADODB.Recordset
Dim strFileName As String
Const conSHEET1 = "Sheet1" 'name of your first worksheet
Const ConWKBK = "\\Server\Projects_2\Office Docs\Template - Summary Reports.xlt" 'full path to my template file
Set objXL = New Excel.Application
With objXL
.Visible = True
Set objWKB = .Workbooks.Open(ConWKBK)
End With
'Populate worksheet
Set rs = DefineRecordset(rptType, JobID, startdate, enddate)
If Not rs.EOF Then 'Make sure the recordset isn't empty
Set objSHT = objWKB.Worksheets(conSHEET1)
objSHT.Range("A6").CopyFromRecordset rs '***DEBUGGER STOPS HERE***
objSHT.Range("A1").value = GetJobName(JobID)
'Format the date column if rpttype = 5
If rptType = 5 Then
objSHT.Range("B:B").Cells.NumberFormat = "mm/dd/yy"
End If
'Make sure range that appears in spreadsheet isn't goofy.
If startdate = "01/01/1900" Then
objSHT.Range("A2").value = "Time and mileage from beginning of project until " & Date
Else
objSHT.Range("A2").value = "Time and Mileage From " & startdate & " to " & enddate
End If
objSHT.Range("A3").value = "Summary created on: " & Now()
strFileName = RptFileName(rptType, JobID)
objSHT.SaveAs strFileName
'objXL.Application.Quit
Else
objXL.Visible = False
MsgBox "There is no data for " & GetJobName(JobID) & " for the selected dates." & vbCrLf & _
"A report has not been created."
End If
Set objSHT = Nothing
Set objWKB = Nothing
Set objXL = Nothing
rs.Close
End Sub