You said you are using the code in the Click event of a button but where exactly did you place the entire code? If the code is in a Standard Module it will throw that error. Or MikeLeBen might be on point. References are in the VBA editor under Tools > References.
I placed my whole code under Option Compare Database. I clicked on the button in design view, then clicked property sheet, onclick, event procedure, and then I pasted the code there. Here's exactly how it looks
Option Compare Database
Private Sub Command28_Click()
Dim rstBooks As DAO.Recordset
Dim lngBookCount As Long
Dim i As Long
Set rstBooks = Me.RecordsetClone
If Not rstBooks.EOF Then
rstBooks.MoveLast
rstBooks.MoveFirst
lngBookCount = rstBooks.RecordCount
Else
MsgBox "There are no records of books by this author."
Exit Sub
End If
Dim objXL As Object
Dim objXLBook As Object
Dim objXLSheet As Object
Dim objRange As Object
Set objXL = CreateObject("Excel.Application")
Set objXLBook = objXL.Workbooks.Open("C:\sampletemplate.xltx.xlsx")
'clean the filename up btw
objXLBook.Application.Visible = True
Set objXLSheet = objXLBook.Worksheets(1)
'dont need this line anymore Set objRange = objXLSheet.Cells.Range("B3")
objXLSheet.Cells.Range("B1") = Author_Name
While rstBooks.EOF = False
For i = 0 To (lngBookCount - 1)
objXLSheet.Cells.Range("B" & (5 + i)) = rstBooks![Online_Book_Name]
objXLSheet.Cells.Range("A" & (5 + i)) = rstBooks![Original_Book_Name]
'turn genre into a column, since every book can have different genre:
objXLSheet.Cells.Range("C" & (5 + i)) = rstBooks![Genre]
rstBooks.MoveNext
Next i
Wend
'these lines are dysfunctional also strData = ComputerName
'these lines are dysfunctional also objRange.Value = strData
Set objXL = Nothing
Set objXLBook = Nothing
Set objXLSheet = Nothing
Set objRange = Nothing
Set rstBooks = Nothing
End Sub