CreateObject("Excel.Application"), процесс Excel продолжает висеть в диспетчере, когда это уже не нужно - VB
Формулировка задачи:
Уважаемые Модераторы все остальные !
Прошу Вас помогите
Программа срабатывает при активизации формы, с помощью CreateObject("Excel.Application") создается объект. В диспетчере задать создается Excel.exe файл. После выполнения всех процедур необходимо чтобы Excel.exe файл закрылся, так как он мешает для дальнейшей работы. Почему-то wb.Close False XL.Quit не срабатывает и весит в диспетчере задать пока не остановишь весь процесс .
Private Sub CommandButton2_Click() Unload Me End Sub Public Sub CommandButton3_Click() Close_insident.Show Unload Me End Sub Private Sub Form_Activate() Dim data(1 To 10) As Variant Dim vrema As Date Dim x As Integer Dim j As Integer Dim q As Integer Dim z As Integer Dim Fail As String Dim w As Integer Dim r As Integer Dim i As Integer Dim wb As Workbook Dim XL As Excel.Application Fail$ = "C:\Temp\new projekt\ewsd.xls" Set XL = CreateObject("Excel.Application") Set wb = XL.Workbooks.Open(Fail) r = 1 Do While wb.Worksheets("Insident").Cells(1).Cells(r).Value <> "" r = r + 1 Loop w = r + 1 q = 1 ' ГЁГ*öèäåГ*ГІ 1 wb.Worksheets("Insident").Activate j = q Do While wb.Worksheets("Insident").Cells(11).Cells(j).Value <> "Îòêðûò" j = j + 1 If j = w Then MsgBox "ÍåîáГ*Г*ðóæåГ*Г® Г*ГҐ îäГ*îãî îòêðûòîãî ГЁГ*öèäåГ*ГІГ*" wb.Close False XL.Quit GoTo Value End If Loop x = j z = j ' äëÿ Г§Г*êðûòèÿ ГЁГ*öèäåГ*ГІГ* 'Г§Г*ïèñûâГ*ГҐГ¬ Г¤Г*Г*Г*ûå ГЁГ§ ГІГ*áëèöû Гў Г¬Г*Г±Г±ГЁГў For i = 1 To 10 With wb.Worksheets("Insident") data(i) = .Cells(x, i).Value End With Next vrema = wb.Worksheets("insident").Cells(2).Cells(j).Value ' ìîæГ*Г® Г§Г*ГЇГЁГ±Г*ГІГј ГІГ*ГЄ vrema = data(2) With ALL_insident 'Íîìåð ГЁГ*öèäåГ*ГІГ* Me.Label1.Caption = data(8) 'ГЌГ*ïðîâëåГ*ГЁГҐ Me.Label2.Caption = data(3) 'TS Me.Label3.Caption = data(4) 'Ïîòðåáèòåëü Me.Label4.Caption = data(10) 'Г„Г*ГІГ* ГЁГ*öèäåГ*ГІГ* Me.Label5.Caption = data(9) 'âðåìÿ ГЁГ*öèäåГ*ГІГ* Me.Label6.Caption = vrema 'ïðå÷èГ*Г* ГЁГ*öèäåГ*ГІГ* Me.Label7.Caption = data(5) 'ГЄГ±ГІГ® Г±Г¤Г*Г« ГЁГ*öèäåГ*ГІ Me.Label8.Caption = data(1) End With q = x + 1 wb.Worksheets("Insident").Activate ' ГЁГ*öèäåГ*ГІ 2 j = q Do While wb.Worksheets("insident").Cells(11).Cells(j).Value <> "Îòêðûò" j = j + 1 If j = w Then MsgBox "ГЋГЎГ*Г*ðóæåГ* îäèГ* îòêðûòûé ГЁГ*öèäåГ*ГІ" wb.Close False XL.Quit GoTo Value End If Loop x = j 'Г§Г*ïèñûâГ*ГҐГ¬ Г¤Г*Г*Г*ûå ГЁГ§ ГІГ*áëèöû Гў Г¬Г*Г±Г±ГЁГў For i = 1 To 10 With ActiveSheet data(i) = .Cells(x, i).Value End With Next vrema = wb.Worksheets("insident").Cells(2).Cells(j).Value ' ìîæГ*Г® Г§Г*ГЇГЁГ±Г*ГІГј ГІГ*ГЄ vrema = data(2) With ALL_insident 'Íîìåð ГЁГ*öèäåГ*ГІГ* Me.Label9.Caption = data(8) 'ГЌГ*ïðîâëåГ*ГЁГҐ Me.Label10.Caption = data(3) 'TS Me.Label11.Caption = data(4) 'Ïîòðåáèòåëü Me.Label12.Caption = data(10) 'Г„Г*ГІГ* ГЁГ*öèäåГ*ГІГ* Me.Label13.Caption = data(9) 'âðåìÿ ГЁГ*öèäåГ*ГІГ* Me.Label14.Caption = vrema 'ïðå÷èГ*Г* ГЁГ*öèäåГ*ГІГ* Me.Label15.Caption = data(5) 'ГЄГ±ГІГ® Г±Г¤Г*Г« ГЁГ*öèäåГ*ГІ Me.Label16.Caption = data(1) End With q = x + 1 ' ГЁГ*öèäåГ*ГІ 3 wb.Worksheets("Insident").Activate j = q Do While wb.Worksheets("insident").Cells(11).Cells(j).Value <> "Îòêðûò" j = j + 1 If j = w Then MsgBox "ГЋГЎГ*Г*ðóæåГ*Г® äâГ* îòêðûòûõ ГЁГ*öèäåГ*ГІГ*" GoTo Value End If Loop x = j 'Г§Г*ïèñûâГ*ГҐГ¬ Г¤Г*Г*Г*ûå ГЁГ§ ГІГ*áëèöû Гў Г¬Г*Г±Г±ГЁГў For i = 1 To 10 With ActiveSheet data(i) = .Cells(x, i).Value End With Next vrema = wb.Worksheets("insident").Cells(2).Cells(j).Value ' ìîæГ*Г® Г§Г*ГЇГЁГ±Г*ГІГј ГІГ*ГЄ vrema = data(2) With ALL_insident 'Íîìåð ГЁГ*öèäåГ*ГІГ* Me.Label17.Caption = data(8) 'ГЌГ*ïðîâëåГ*ГЁГҐ Me.Label18.Caption = data(3) 'TS Me.Label19.Caption = data(4) 'Ïîòðåáèòåëü Me.Label20.Caption = data(10) 'Г„Г*ГІГ* ГЁГ*öèäåГ*ГІГ* Me.Label21.Caption = data(9) 'âðåìÿ ГЁГ*öèäåГ*ГІГ* Me.Label22.Caption = vrema 'ïðå÷èГ*Г* ГЁГ*öèäåГ*ГІГ* Me.Label23.Caption = data(5) 'ГЄГ±ГІГ® Г±Г¤Г*Г« ГЁГ*öèäåГ*ГІ Me.Label24.Caption = data(1) End With q = x + 1 ' ГЁГ*öèäåГ*ГІ 4 j = q Do While wb.Worksheets("insident").Cells(11).Cells(j).Value <> "Îòêðûò" j = j + 1 If j = w Then MsgBox "ГЋГЎГ*Г*ðóæåГ*Г® òðè îòêðûòûõ ГЁГ*öèäåГ*ГІГ*" wb.Close False XL.Quit GoTo Value End If Loop x = j 'Г§Г*ïèñûâГ*ГҐГ¬ Г¤Г*Г*Г*ûå ГЁГ§ ГІГ*áëèöû Гў Г¬Г*Г±Г±ГЁГў For i = 1 To 10 With ActiveSheet data(i) = .Cells(x, i).Value End With Next vrema = wb.Worksheets("insident").Cells(2).Cells(j).Value ' ìîæГ*Г® Г§Г*ГЇГЁГ±Г*ГІГј ГІГ*ГЄ vrema = data(2) With ALL_insident 'Íîìåð ГЁГ*öèäåГ*ГІГ* Me.Label25.Caption = data(8) 'ГЌГ*ïðîâëåГ*ГЁГҐ Me.Label26.Caption = data(3) 'TS Me.Label27.Caption = data(4) 'Ïîòðåáèòåëü Me.Label28.Caption = data(10) 'Г„Г*ГІГ* ГЁГ*öèäåГ*ГІГ* Me.Label29.Caption = data(9) 'âðåìÿ ГЁГ*öèäåГ*ГІГ* Me.Label30.Caption = vrema 'ïðå÷èГ*Г* ГЁГ*öèäåГ*ГІГ* Me.Label31.Caption = data(5) 'ГЄГ±ГІГ® Г±Г¤Г*Г« ГЁГ*öèäåГ*ГІ Me.Label32.Caption = data(1) End With q = x + 1 ' ГЁГ*öèäåГ*ГІ 5 j = q Do While wb.Worksheets("insident").Cells(11).Cells(j).Value <> "Îòêðûò" j = j + 1 If j = w Then MsgBox "ГЋГЎГ*Г*ðóæåГ*Г® ÷åòûðå îòêðûòûõ ГЁГ*öèäåГ*ГІГ*" wb.Close False XL.Quit GoTo Value End If Loop x = j 'Г§Г*ïèñûâГ*ГҐГ¬ Г¤Г*Г*Г*ûå ГЁГ§ ГІГ*áëèöû Гў Г¬Г*Г±Г±ГЁГў For i = 1 To 10 With ActiveSheet data(i) = .Cells(x, i).Value End With Next vrema = wb.Worksheets("insident").Cells(2).Cells(j).Value ' ìîæГ*Г® Г§Г*ГЇГЁГ±Г*ГІГј ГІГ*ГЄ vrema = data(2) With ALL_insident 'Íîìåð ГЁГ*öèäåГ*ГІГ* Me.Label33.Caption = data(8) 'ГЌГ*ïðîâëåГ*ГЁГҐ Me.Label34.Caption = data(3) 'TS Me.Label35.Caption = data(4) 'Ïîòðåáèòåëü Me.Label36.Caption = data(10) 'Г„Г*ГІГ* ГЁГ*öèäåГ*ГІГ* Me.Label37.Caption = data(9) 'âðåìÿ ГЁГ*öèäåГ*ГІГ* Me.Label38.Caption = vrema 'ïðå÷èГ*Г* ГЁГ*öèäåГ*ГІГ* Me.Label39.Caption = data(5) 'ГЄГ±ГІГ® Г±Г¤Г*Г« ГЁГ*öèäåГ*ГІ Me.Label40.Caption = data(1) End With q = x + 1 ' ГЁГ*öèäåГ*ГІ 6 j = q Do While wb.Worksheets("insident").Cells(11).Cells(j).Value <> "Îòêðûò" j = j + 1 If j = w Then MsgBox "ГЋГЎГ*Г*ðóæåГ*Г® ГЇГїГІГј îòêðûòûõ ГЁГ*öèäåГ*ГІГ*" wb.Close False XL.Quit GoTo Value End If Loop x = j 'Г§Г*ïèñûâГ*ГҐГ¬ Г¤Г*Г*Г*ûå ГЁГ§ ГІГ*áëèöû Гў Г¬Г*Г±Г±ГЁГў For i = 1 To 10 With ActiveSheet data(i) = .Cells(x, i).Value End With Next vrema = wb.Worksheets("insident").Cells(2).Cells(j).Value ' ìîæГ*Г® Г§Г*ГЇГЁГ±Г*ГІГј ГІГ*ГЄ vrema = data(2) With ALL_insident 'Íîìåð ГЁГ*öèäåГ*ГІГ* Me.Label41.Caption = data(8) 'ГЌГ*ïðîâëåГ*ГЁГҐ Me.Label42.Caption = data(3) 'TS Me.Label43.Caption = data(4) 'Ïîòðåáèòåëü Me.Label44.Caption = data(10) 'Г„Г*ГІГ* ГЁГ*öèäåГ*ГІГ* Me.Label45.Caption = data(9) 'âðåìÿ ГЁГ*öèäåГ*ГІГ* Me.Label46.Caption = vrema 'ïðå÷èГ*Г* ГЁГ*öèäåГ*ГІГ* Me.Label47.Caption = data(5) 'ГЄГ±ГІГ® Г±Г¤Г*Г« ГЁГ*öèäåГ*ГІ Me.Label48.Caption = data(1) End With q = x + 1 ' ГЁГ*öèäåГ*ГІ 7 j = q Do While wb.Worksheets("insident").Cells(11).Cells(j).Value <> "Îòêðûò" j = j + 1 If j = w Then MsgBox "ГЋГЎГ*Г*ðóæåГ*Г® ГёГҐГ±ГІГј îòêðûòûõ ГЁГ*öèäåГ*ГІГ*" wb.Close False XL.Quit GoTo Value End If Loop x = j 'Г§Г*ïèñûâГ*ГҐГ¬ Г¤Г*Г*Г*ûå ГЁГ§ ГІГ*áëèöû Гў Г¬Г*Г±Г±ГЁГў For i = 1 To 10 With ActiveSheet data(i) = .Cells(x, i).Value End With Next vrema = wb.Worksheets("insident").Cells(2).Cells(j).Value ' ìîæГ*Г® Г§Г*ГЇГЁГ±Г*ГІГј ГІГ*ГЄ vrema = data(2) With ALL_insident 'Íîìåð ГЁГ*öèäåГ*ГІГ* Me.Label49.Caption = data(8) 'ГЌГ*ïðîâëåГ*ГЁГҐ Me.Label50.Caption = data(3) 'TS Me.Label51.Caption = data(4) 'Ïîòðåáèòåëü Me.Label52.Caption = data(10) 'Г„Г*ГІГ* ГЁГ*öèäåГ*ГІГ* Me.Label53.Caption = data(9) 'âðåìÿ ГЁГ*öèäåГ*ГІГ* Me.Label54.Caption = vrema 'ïðå÷èГ*Г* ГЁГ*öèäåГ*ГІГ* Me.Label55.Caption = data(5) 'ГЄГ±ГІГ® Г±Г¤Г*Г« ГЁГ*öèäåГ*ГІ Me.Label56.Caption = data(1) End With q = x + 1 ' ГЁГ*öèäåГ*ГІ 8 j = q Do While wb.Worksheets("insident").Cells(11).Cells(j).Value <> "Îòêðûò" j = j + 1 If j = w Then MsgBox "ГЋГЎГ*Г*ðóæåГ*Г® ñåìü îòêðûòûõ ГЁГ*öèäåГ*ГІГ*" wb.Close False XL.Quit GoTo Value End If Loop x = j 'Г§Г*ïèñûâГ*ГҐГ¬ Г¤Г*Г*Г*ûå ГЁГ§ ГІГ*áëèöû Гў Г¬Г*Г±Г±ГЁГў For i = 1 To 10 With ActiveSheet data(i) = .Cells(x, i).Value End With Next vrema = wb.Worksheets("insident").Cells(2).Cells(j).Value ' ìîæГ*Г® Г§Г*ГЇГЁГ±Г*ГІГј ГІГ*ГЄ vrema = data(2) With ALL_insident 'Íîìåð ГЁГ*öèäåГ*ГІГ* Me.Label57.Caption = data(8) 'ГЌГ*ïðîâëåГ*ГЁГҐ Me.Label58.Caption = data(3) 'TS Me.Label59.Caption = data(4) 'Ïîòðåáèòåëü Me.Label60.Caption = data(10) 'Г„Г*ГІГ* ГЁГ*öèäåГ*ГІГ* Me.Label61.Caption = data(9) 'âðåìÿ ГЁГ*öèäåГ*ГІГ* Me.Label62.Caption = vrema 'ïðå÷èГ*Г* ГЁГ*öèäåГ*ГІГ* Me.Label63.Caption = data(5) 'ГЄГ±ГІГ® Г±Г¤Г*Г« ГЁГ*öèäåГ*ГІ Me.Label64.Caption = data(1) End With q = x + 1 ' ГЁГ*öèäåГ*ГІ 9 j = q Do While wb.Worksheets("insident").Cells(11).Cells(j).Value <> "Îòêðûò" j = j + 1 If j = w Then MsgBox "ГЋГЎГ*Г*ðóæåГ*Г® âîñåìü îòêðûòûõ ГЁГ*öèäåГ*ГІГ*" wb.Close False XL.Quit GoTo Value End If Loop x = j 'Г§Г*ïèñûâГ*ГҐГ¬ Г¤Г*Г*Г*ûå ГЁГ§ ГІГ*áëèöû Гў Г¬Г*Г±Г±ГЁГў For i = 1 To 10 With ActiveSheet data(i) = .Cells(x, i).Value End With Next vrema = wb.Worksheets("insident").Cells(2).Cells(j).Value ' ìîæГ*Г® Г§Г*ГЇГЁГ±Г*ГІГј ГІГ*ГЄ vrema = data(2) With ALL_insident 'Íîìåð ГЁГ*öèäåГ*ГІГ* Me.Label65.Caption = data(8) 'ГЌГ*ïðîâëåГ*ГЁГҐ Me.Label66.Caption = data(3) 'TS Me.Label67.Caption = data(4) 'Ïîòðåáèòåëü Me.Label68.Caption = data(10) 'Г„Г*ГІГ* ГЁГ*öèäåГ*ГІГ* Me.Label69.Caption = data(9) 'âðåìÿ ГЁГ*öèäåГ*ГІГ* Me.Label70.Caption = vrema 'ïðå÷èГ*Г* ГЁГ*öèäåГ*ГІГ* Me.Label71.Caption = data(5) 'ГЄГ±ГІГ® Г±Г¤Г*Г« ГЁГ*öèäåГ*ГІ Me.Label72.Caption = data(1) End With q = x + 1 ' ГЁГ*öèäåГ*ГІ 10 j = q Do While wb.Worksheets("insident").Cells(11).Cells(j).Value <> "Îòêðûò" j = j + 1 If j = w Then MsgBox "ГЋГЎГ*Г*ðóæåГ*Г® äåâÿòü îòêðûòûõ ГЁГ*öèäåГ*ГІГ*" wb.Close False XL.Quit GoTo Value End If Loop x = j 'Г§Г*ïèñûâГ*ГҐГ¬ Г¤Г*Г*Г*ûå ГЁГ§ ГІГ*áëèöû Гў Г¬Г*Г±Г±ГЁГў For i = 1 To 10 With ActiveSheet data(i) = .Cells(x, i).Value End With Next vrema = wb.Worksheets("insident").Cells(2).Cells(j).Value ' ìîæГ*Г® Г§Г*ГЇГЁГ±Г*ГІГј ГІГ*ГЄ vrema = data(2) With ALL_insident 'Íîìåð ГЁГ*öèäåГ*ГІГ* Me.Label73.Caption = data(8) 'ГЌГ*ïðîâëåГ*ГЁГҐ Me.Label74.Caption = data(3) 'TS Me.Label75.Caption = data(4) 'Ïîòðåáèòåëü Me.Label76.Caption = data(10) 'Г„Г*ГІГ* ГЁГ*öèäåГ*ГІГ* Me.Label77.Caption = data(9) 'âðåìÿ ГЁГ*öèäåГ*ГІГ* Me.Label78.Caption = vrema 'ïðå÷èГ*Г* ГЁГ*öèäåГ*ГІГ* Me.Label79.Caption = data(5) 'ГЄГ±ГІГ® Г±Г¤Г*Г« ГЁГ*öèäåГ*ГІ Me.Label80.Caption = data(1) End With Value: wb.Close False XL.Quit End Sub
Решение задачи: «CreateObject("Excel.Application"), процесс Excel продолжает висеть в диспетчере, когда это уже не нужно»
textual
Листинг программы
объект.Close Set объект = Nothing
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д