Results 1 to 5 of 5

Thread: Object Variable Not Set Error when closing Excel workbook from PowerPoint

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,096
    Location
    If you have referenced Excel why declare xlApp and xlWorkbook as Objects? Personally I would use late binding and not reference Excel. It may be a little slower but can be safer.

    The problem though is using ActiveWorkbook.Save use xlWorkbook.Save as in my previous post and see if that works. This is both if you use early or late binding

    UPDATE

    I just checked and ActiveWorkBook did work if Excel is properly referenced but I would still use xlWorkbook

    Sub RetrieveExcelValue()'Excel is referenced
    Dim xlApp As Excel.Application
    Dim xlWorkBook As Excel.Workbook
    Dim ExcelValue As Double
    
    
    Set xlApp = CreateObject("Excel.Application")
    
    
    xlApp.Visible = True
    Set xlWorkBook = xlApp.Workbooks.Open("C:/users/johns/desktop/test.xlsx")' my path of course
    
    
    ExcelValue = xlWorkBook.Worksheets("PPT Transfer").Range("C5").Value
    xlWorkBook.Save
    xlApp.Quit
    
    
    MsgBox ("The value of this range in Excel is " & ExcelValue)
    End Sub
    Last edited by John Wilson; 02-19-2018 at 11:51 AM.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •