Consulting

Results 1 to 10 of 10

Thread: Kill Excel after user close userform

  1. #1

    Kill Excel after user close userform

    Hi guys,
    I am having a problem with excel running after the Userform is closed, I think what I have supposed to end the application but it doesn't, it keeps excel running in the background and I have to end the process with task manager.
    I created a vbs file to copy a file to the temp folder and run a macro which opens excel and the userform.
    Any help is appreciate it.

    This is the vbs script that copy and opens the macro:
    Dim FSO
    Set FSO = CreateObject("Scripting.FileSystemObject")
    FSO.CopyFile "C:\pdfv6.xlsm", "C:\Windows\Temp\"
    Set objExcel = CreateObject("Excel.Application")
    objExcel.Application.Run "'C:\Windows\Temp\pdfv6.xlsm'!module1.macro1"
    objExcel.DisplayAlerts = False
    objExcel.Application.Quit
    Set objExcel = Nothing
    And this is part of the vba module:
    Sub Macro1()
    Application.Visible = False
    UserForm1.Show
    End Sub

    And this is the Sub that deals with closing the Userform and the application.
    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
        If CloseMode = 0 Then
        ThisWorkbook.Close savechanges = False
        Application.Quit
               End
        End If
    End Sub

  2. #2
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    613
    Location
    .
    Try changing this :

    Dim FSO 
    Set FSO = CreateObject("Scripting.FileSystemObject") 
    FSO.CopyFile "C:\pdfv6.xlsm", "C:\Windows\Temp\" 
    Set objExcel = CreateObject("Excel.Application") 
    objExcel.Application.Run "'C:\Windows\Temp\pdfv6.xlsm'!module1.macro1" 
    objExcel.DisplayAlerts = False 
    objExcel.Application.Quit               '<<--------------------- Invert these two lines
    Set objExcel = Nothing         '<<--------------------- Invert these two lines
    
    
    
    
    
    
    Dim FSO 
    Set FSO = CreateObject("Scripting.FileSystemObject") 
    FSO.CopyFile "C:\pdfv6.xlsm", "C:\Windows\Temp\" 
    Set objExcel = CreateObject("Excel.Application") 
    objExcel.Application.Run "'C:\Windows\Temp\pdfv6.xlsm'!module1.macro1" 
    objExcel.DisplayAlerts = False 
    Set objExcel = Nothing         '<<--------------------- Inverted
    objExcel.Application.Quit               '<<--------------------- Inverted

  3. #3
    I am getting this error once I close the userform and the excel.exe *32 is still running on the Windows Task Manager

    Line: 5
    Char: 1
    Error: Unknown runtime error
    Code: 800A9C68
    Source: Microsoft VBScript runtime error

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) 
        If CloseMode = 0 Then 
    Unload Me '<-------------
            ThisWorkbook.Close savechanges = False 
            Application.Quit 
            End 
        End If 
    End Sub
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  5. #5
    I am still getting the same error, but now at least when I click ok on the error dialog box it clears the excel from the processes.
    I need to figure out why I am getting this error.

  6. #6
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    The problem is in the vbsacript
    Try commenting out this line
    'objExcel.Application.Quit
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  7. #7
    Still, the same problem.

  8. #8
    I found the problem. I was using Application.Quit twice Once in the vbs script and then when I was closing the form. I got rid of the one in the vbs script and everything is fine now. thank you for your help.

  9. #9
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    ?
    The problem is in the vbsacript
    Try commenting out this line
          'objExcel.Application.Quit
    Still, the same problem.
    I found the problem. I was using Application.Quit twice Once in the vbs script and then when I was closing the form. I got rid of the one in the vbs script and everything is fine now.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  10. #10
    Samt., I am sorry. I have to give you credit for this.
    This is what had to do.

    Remove these two lines from the vbs script:
    'Set objExcel = Nothing
    'objExcel.Application.Quit

    For some reason it wasn't working before.
    Thanks a lot for your help.

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
  •