Late binding to avoid MISSING:Microsoft Excel 15.0 Object Library

NENER

New member
Joined
Jun 28, 2016
Messages
9
Reaction score
0
Points
0
I have people on Access 2010 and 2013. I've tried to change my code to late binding to avoid the missing reference, but it's I'm still getting the missing reference. Where did I go wrong? Thanks in advance.

Code:
Private Sub sendquotes_Click()


'  Excel constants:
  Const strcXLPath As String = "C:\Users\amw\AppData\Roaming\Microsoft\Templates\Sales Pipeline Quote Report.xltx"
  Const strcWorksheetName As String = "Sales Pipeline Quote Report"
  Const strcCellAddress As String = "A5"


    
  
  '  Access constants:
  Const strcQueryName As String = "q_SalesPipeLineQuotesCurMo"
  '  Excel Objects:
  Dim objXL As Object ' Excel.Application
  Dim objWBK As Object ' Excel.Workbook
  Dim objWS As Object ' Excel.Worksheet
  Dim objRNG As Object ' Excel.Range
  
  '  DAO objects:
  Dim objDB As DAO.Database
  Dim objQDF As DAO.QueryDef
  Dim objrs As DAO.Recordset
  Dim objQDFT As DAO.QueryDef
  Dim objQDFW As DAO.QueryDef
  
 On Error GoTo Error_Exit_SaveRecordsetToExcelRange
  
  
  
  '  Open a DAO recordset on the query:
  Set objDB = CurrentDb()
  Set objQDF = objDB.QueryDefs(strcQueryName)
  Set objrs = objQDF.OpenRecordset
  
  '  Open Excel and point to the cell where
  '  the recordset is to be inserted:
  ' Set objXL = New Excel.Application
  Set objXL = CreateObject("Excel.Application")
  objXL.Visible = True
  Set objWBK = objXL.Workbooks.Open(strcXLPath)
  Set objWS = objWBK.Worksheets(strcWorksheetName)
    
    With objWS
        .Cells(1, 2).Value = DateSerial(Year(Date), Month(Date), 1)
        .Cells(2, 2).Value = DateSerial(Year(Date), Month(Date) + 1, 1 - 1)
    End With
        
  Set objRNG = objWS.Range(strcCellAddress)
   objRNG.CopyFromRecordset objrs
  




  '  Destroy objects:
  GoSub CleanUp
  
Exit_SaveRecordsetToExcelRange:






  Exit Sub
  
CleanUp:


  '  Destroy Excel objects:
  Set objRNG = Nothing
  Set objWS = Nothing
  Set objWBK = Nothing
  Set objXL = Nothing
  
  '  Destroy DAO objects:
  If Not objrs Is Nothing Then
    objrs.Close
    Set objrs = Nothing
  End If
  Set objQDF = Nothing
  Set objDB = Nothing
  
  Return
  
Error_Exit_SaveRecordsetToExcelRange:


  MsgBox "Error " & Err.Number _
    & vbNewLine & vbNewLine _
    & Err.Description, _
    vbExclamation + vbOKOnly, _
    "Error Information"
    
  GoSub CleanUp
  Resume Exit_SaveRecordsetToExcelRange


End Sub
 
Last edited by a moderator:
Please use code tags !

and use

Code:
MsgBox "Error " & Err.Number & vbLf & vbLf & Err.Description, , "Error Information"
 
But it's too much code for a simple task:

Code:
Sub M_snb()
  Set w00 = Workbooks.open("C:\Users\amw\AppData\Roaming\Microsoft\Templates\Sales Pipeline Quote Report.xltx")

  with  w00.sheets("Sales Pipeline Quote Report")
    .Cells(1, 2)=date
    .Cells(2, 2)=dateadd("m",1,date)-1
  end with

  With CreateObject("ADODB.recordset")
    .Open "SELECT * FROM q_SalesPipeLineQuotesCurMo", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & currentDB.fullname
    w00.Sheets("Sales Pipeline Quote Report").Cells(5, 1).CopyFromRecordset .DataSource
  End With
End Sub
 
Since you're using late binding already in the code (Set objXL = CreateObject("Excel.Application")) you don't need the reference anymore. Just remove it, then it won't be reported as missing.
 
Doesn't work

I get the following Compile Error:
Method or data member not found

Cursor goes to CurrentDb.FullName



But it's too much code for a simple task:

Code:
Sub M_snb()
  Set w00 = Workbooks.open("C:\Users\amw\AppData\Roaming\Microsoft\Templates\Sales Pipeline Quote Report.xltx")

  with  w00.sheets("Sales Pipeline Quote Report")
    .Cells(1, 2)=date
    .Cells(2, 2)=dateadd("m",1,date)-1
  end with

  With CreateObject("ADODB.recordset")
    .Open "SELECT * FROM q_SalesPipeLineQuotesCurMo", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & currentDB.fullname
    w00.Sheets("Sales Pipeline Quote Report").Cells(5, 1).CopyFromRecordset .DataSource
  End With
End Sub
 
So sorry. I'm a newbie on vba. Could you be more specific on which line to delete?
 
In the visual basic editor, you should have a dropdown Tools, in there choose References…, and you should see among the references a reference to Microsoft Excel 15.0 object Library, or very similar. Remove the tick in the tickbox next to it.
 
In the visual basic editor, you should have a dropdown Tools, in there choose References…, and you should see among the references a reference to Microsoft Excel 15.0 object Library, or very similar. Remove the tick in the tickbox next to it.

Ok. will do. I'm an idiot. I'd continued to uncheck 15.0 and check Microsoft Excel 14.0 object library. Banging head on desk.
 
Yes, uncheck all refs to any Excel object library. (You're in Access, right?)
 
currentdb.name instead of currentdb.fullname

Code:
Sub M_snb()
  Set w00 = Workbooks.open("C:\Users\amw\AppData\Roaming\Microsoft\Templates\Sales Pipeline Quote Report.xltx")
  with  w00.sheets("Sales Pipeline Quote Report")
    .Cells(1, 2)=date
    .Cells(2, 2)=dateadd("m",1,date)-1
  end with

  With CreateObject("ADODB.recordset")
    .Open "SELECT * FROM q_SalesPipeLineQuotesCurMo", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & currentDB.name
    w00.Sheets("Sales Pipeline Quote Report").Cells(5, 1).CopyFromRecordset .DataSource
  End With
End Sub
 
Crashes on:

Set w00 = Workbooks.open("C:\Users\amw\AppData\Roaming\Microsoft\Templates\Sales Pipeline Quote Report.xltx")
 
Code:
Sub M_snb()
  Set w00 = Getobject("C:\Users\amw\AppData\Roaming\Microsoft\Templates\Sales Pipeline Quote Report.xltx")
   with  w00.sheets("Sales Pipeline Quote Report")
     .Cells(1, 2)=date
     .Cells(2, 2)=dateadd("m",1,date)-1
   end with

  With CreateObject("ADODB.recordset")
     .Open "SELECT * FROM q_SalesPipeLineQuotesCurMo", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & currentDB.name
     w00.Sheets("Sales Pipeline Quote Report").Cells(5, 1).CopyFromRecordset .DataSource
   End With
 End Sub
 
Copied and pasted code. Run-time error '-2147467259 (800004005)' Unrecognozed database format 'mydatabase.accdb'.
 
Changed code from "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" to 'Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" to account for Access 2010. Code worked passed that. Now stuck on Run-time error. Method 'CopyFrom Recordset' of object Range failed.
 
Back
Top