PDA

View Full Version : Kill Excel after user close userform



elyfrank
10-26-2017, 03:56 PM
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

Logit
10-26-2017, 04:18 PM
.
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

elyfrank
10-26-2017, 04:50 PM
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

SamT
10-26-2017, 05:36 PM
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

elyfrank
10-26-2017, 05:47 PM
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.

SamT
10-27-2017, 04:47 AM
The problem is in the vbsacript
Try commenting out this line

'objExcel.Application.Quit

elyfrank
10-27-2017, 08:37 AM
Still, the same problem.

elyfrank
10-27-2017, 11:41 AM
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.

SamT
10-27-2017, 01:50 PM
?

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.

elyfrank
10-27-2017, 04:26 PM
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.