Excel instance will not close when using .Range().Sort in VBA

  • I have some code that creates and writes to a workbook from within MS Access..


    The code does not save the workbook, so it opens as 'Book1.xls'.


    I have found the problem line of code below... This sorts the data..


    If this line is executed, then once the user closes Book1.xls there is still an instance of Excel running. However, if i comment this line then the Excel instance closes as expected.


    Anyone have ideas how to fix this ?


    Code
    .Range(.Cells(3, 1), .Cells(500, 255)).Sort Key1:=Range("J3"), Order1:=xlAscending, Header:=xlGuess, _
                OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal


    I have posted to another forum, but no response so far..

    HTML
    http://www.mrexcel.com/forum/excel-questions/850931-visual-basic-applications-excel-instance-after-excel-closed-user.html
  • Re: Excel instance will not close when using .Range().Sort in VBA


    if you are using api of excel from ms access then you have to close the instance of the excel api from the access itself hence you are not saving the excel file then it will not get closed as you want it to do


    i think the sorting code doesnt has any suspicious line of code as per me.

  • Re: Excel instance will not close when using .Range().Sort in VBA


    Hi


    This has now been solved by a member on the other forum... Thanks

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!