Results 1 to 5 of 5
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    Trouble closing an Excel file


    I can't figure out what's going on with the situation depicted in the screenshot below? Any ideas?

    Click image for larger version. 

Name:	000.jpg 
Views:	15 
Size:	158.5 KB 
ID:	32474

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    it means XLSAPP was erased.
    most likely set xlsapp = nothing.

    dont set that until AFTER the close and save.

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    dont set that until AFTER the close and save.
    I don't understand your note in that you'll see in the code that I don't set the object of Nothing until after the save.

    If I remove "SaveChanges:=False" and let the close disposition default it works fine, so the problem lies elsewhere.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    do you have xlsApps declared at the very top of your module? I don't see how Form_Close knows what it is.
    EDIT:
    I also think the syntax is .Close False but not sure. What you have looks more like Excel syntax.
    Then again, you don't specify which workbook in the Workbooks collection you are trying to close. You specify which one to add to the collection (sgtrxlFileName) but not which one to close. When doing this, I always create objects for the app, book, and sheet. That way, it's clear and easy as to which one I want to refer to. Haven't done this for a while so I'm guessing a bit, but I lean towards Access not knowing which object to close.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Turns out I have to close each Workbook in the collection one at a time. xlsApp object is DIM'd, Set and Open elsewhere in the module. You'll notice the the code doesn't run unless the Workbook is open boolean is True.

    Code:
    If bolWSOpen Then
        
        For Each WB In xlsApp.Workbooks
            WB.Close SaveChanges:=False
        Next
        xlsApp.Quit
        Set xlsApp = Nothing
        
    End If

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Closing Excel file
    By Dave_D in forum Programming
    Replies: 3
    Last Post: 07-06-2016, 10:42 PM
  2. Replies: 5
    Last Post: 05-25-2016, 12:43 PM
  3. Trouble Closing Form with VBA
    By RAOtto01 in forum Forms
    Replies: 2
    Last Post: 12-11-2015, 02:37 PM
  4. Replies: 7
    Last Post: 08-07-2014, 06:07 PM
  5. I'm not closing off Excel properly I think?
    By stildawn in forum Modules
    Replies: 7
    Last Post: 05-01-2014, 05:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums