Code will not open Excel

I am trying to open Excel from ACCESS, but keep getting the error message.  It seems so simple so I do not understand what is wrong.  References to the Excel library are set.
Private Sub cmdOpenExcel_Click()
Dim xlApp As Object
Dim xlWB As Object
Set xlApp = CreateObject("Excel.Application")
    With xlWB
        .Workbooks.Open ("Z:\LossPreventionDatabases\Reports.xls")
        .Visible = True
    End With
Set xlApp = Nothing
Set xlWB = Nothing
 
End Sub

Open in new window

ssmith94015Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
bigdaddyz99Connect With a Mentor Commented:
You are not creating your workbook object before you reference it.

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open _
    ("Z:\LossPreventionDatabases\Reports.xls")
0
 
ssmith94015Author Commented:
For pete's sake, yes.  I missed that completely.
0
All Courses

From novice to tech pro — start learning today.