Object Variable Not Set Error when closing Excel workbook from PowerPoint
I have code in PowerPoint that opens Excel, retrieves a value from a cell, displays a message box with the cell's value and finally closes the workbook followed by the application.
The first time I run the code in PowerPoint, everything works just fine. When I run the same code again, I get a "Run-time error 91" "Object variable or With block variable not set. Any ideas on what is causing this? Below is my code:
PS: technically I don't need to run the same code again but am curious. As this project gets more involved, would be nice to know the cause of this error so I can avoid it in other coding projects--Thanks.
Private Sub RetrieveExcelValue()
Dim xlApp As Object
Dim xlWorkBook As Object
Dim ExcelValue As Double
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWorkBook = xlApp.Workbooks.Open("E:\Special Projects\PPT Project for Matthew Orenchuk\Cross Flow Skid EER.XLSM", True, False)
ExcelValue = xlWorkBook.Worksheets("PPT Transfer").Range("C5").Value
MsgBox ("The value of this range in Excel is " & ExcelValue)
ActiveWorkbook.Save
xlApp.Quit
End Sub