Remove Excel task from Task manager after running from Access using VBA

后端 未结 2 1963
情歌与酒
情歌与酒 2020-12-02 01:28

I will now take the opportunity to ask here, I have really tried a lot of different way, but it seems that I am not able to be able to close the Excel task in task-manger, I

相关标签:
2条回答
  • 2020-12-02 01:46
    Columns("A:F").EntireColumn.AutoFit
    

    Adding as an answer just in case. Fully qualify this with the worksheet name and try again. This same problem was a huge bother to me too. You have to qualify 100% of your references, no matter what. Also, be super careful about using With statements on ranges, worksheets etc. So change it to ObjWorksheet.Columns("A:F")... instead

    0 讨论(0)
  • 2020-12-02 01:47

    In the comments you mentioned that you had reset your code (i.e. pressed the stop button). This means that the portion of your code that kills excel did not run, thus leaving an open session of excel. There is a small (possibly semantic) issue with your code, but I don't believe that's what was causing your issue. Regardless, you should properly shut down the application like this.

    ExitSub:
        If Not objWorksheet Is Nothing Then
            set objWorksheet = Nothing
        End If
        ' You have to check for the workbook's existence before 
        '    you try to close something that isn't there. This avoids runtime errors.
        '    Since your error handler points you back here, this code always runs, so
        '    The workbook might not be open.
        If Not objWorkbook Is Nothing Then
            objWorkbook.close
            Set objWorkbook = Nothing
        End If
        ' Same goes for quitting the application
        If Not objExcel Is Nothing Then
            objExcel.Quit
            Set objExcel = Nothing
        End If
    
        Exit Sub
    Error_Handler:
        ' error handling code here
         Resume ExitSub
    End Sub
    
    0 讨论(0)
提交回复
热议问题