Close EXCEL.EXE process

  • Thread starter Mikko Rantanen via OfficeKB.com
  • Start date
M

Mikko Rantanen via OfficeKB.com

Hi

I need to kill Excel process totaly.
After excel is close a Excel.exe process stays on.
How can I close excel for good ?

Regars
Mikko

I have used this macro to open workbook

Sub chart()
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim oRng As Excel.Range
Dim ExcelWasNotRunning As Boolean
Dim WorkbookToWorkOn As String

'specify the workbook to work on
WorkbookToWorkOn = "C:\Documents and Settings\All Users\Huoltoraportti\
chart.xls"

'If Excel is running, get a handle on it; otherwise start a new instance of
Excel
On Error Resume Next
Set oXL = GetObject(, "Excel.Application")

If Err Then
ExcelWasNotRunning = True
Set oXL = New Excel.Application
End If

On Error GoTo Err_Handler

'If you want Excel to be visible, you could add the line: oXL.Visible =
True here; but your code will run faster if you don't make it visible

'Open the workbook
Set oWB = oXL.Workbooks.Open(FileName:=WorkbookToWorkOn)

'Process each of the spreadsheets in the workbook
'For Each oSheet In oXL.ActiveWorkbook.Worksheets
'put guts of your code here
'get next sheet
Sheets("Taul1").Select
Range("B2").Select
ActiveCell.FormulaR1C1 = Me.TextBox1.Value
Range("C2").Select
ActiveCell.FormulaR1C1 = Me.TextBox2.Value
Range("D2").Select
ActiveCell.FormulaR1C1 = Me.TextBox3.Value
Range("E2").Select
ActiveCell.FormulaR1C1 = Me.TextBox4.Value
Range("F2").Select
ActiveCell.FormulaR1C1 = Me.TextBox5.Value
Range("G2").Select
ActiveCell.FormulaR1C1 = Me.TextBox6.Value
Range("H2").Select
ActiveCell.FormulaR1C1 = Me.TextBox7.Value
Range("I2").Select
ActiveCell.FormulaR1C1 = Me.TextBox8.Value
Range("J2").Select
ActiveCell.FormulaR1C1 = Me.TextBox9.Value
Range("K2").Select
ActiveCell.FormulaR1C1 = Me.TextBox10.Value
Range("L2").Select
ActiveCell.FormulaR1C1 = Me.TextBox11.Value
Range("M2").Select
ActiveCell.FormulaR1C1 = Me.TextBox12.Value
Range("B3").Select
ActiveCell.FormulaR1C1 = Me.TextBox13.Value
Range("C3").Select
ActiveCell.FormulaR1C1 = Me.TextBox14.Value
Range("D3").Select
ActiveCell.FormulaR1C1 = Me.TextBox15.Value
Range("E3").Select
ActiveCell.FormulaR1C1 = Me.TextBox16.Value
Range("F3").Select
ActiveCell.FormulaR1C1 = Me.TextBox17.Value
Range("G3").Select
ActiveCell.FormulaR1C1 = Me.TextBox18.Value
Range("H3").Select
ActiveCell.FormulaR1C1 = Me.TextBox19.Value
Range("I3").Select
ActiveCell.FormulaR1C1 = Me.TextBox20.Value
Range("J3").Select
ActiveCell.FormulaR1C1 = Me.TextBox21.Value
Range("K3").Select
ActiveCell.FormulaR1C1 = Me.TextBox22.Value
Range("L3").Select
ActiveCell.FormulaR1C1 = Me.TextBox23.Value
Range("M3").Select
ActiveCell.FormulaR1C1 = Me.TextBox24.Value
Range("M4").Select
Sheets("Kaavio1").Select
'Next oSheet

If ExcelWasNotRunning Then
'oXL.SaveWorkspace
oXL.DisplayAlerts = False
oXL.Application.Workbooks.Close
oXL.Quit
End If

'Make sure you release object references.
Set oRng = Nothing
Set oSheet = Nothing
Set oWB = Nothing
Set oXL = Nothing

'quit
Exit Sub

Err_Handler:
MsgBox WorkbookToWorkOn & " caused a problem. " & Err.Description,
vbCritical, _
"Error: " & Err.Number
If ExcelWasNotRunning Then
oXL.Quit
End If

End Sub
 
P

Perry

Several ingredients to improve:
Try to get the grips of below code sequence:

Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
Dim oSH As Excel.Worksheet
Dim oRng As Excel.Range
Dim xlNotRun As Boolean
Dim iRow As integer
Dim iCol as integer, iStart as integer
iStart = 1

On Local Error GoTo xlNotRunning
Set oXL = GetObject(, "Excel.Application")

bmkOpenWorkbook:
Set oWB = _
oXL Workbooks.Open(WorkbookToWorkOn)

Set oSH = Sheets("Taul1")
On Local Error Goto ErrProcessingSheet
For iRow = 1 to 2
For iCol= iStart to iStart + 12

'Note oRng and the TextBox representation
'in this section:
Set oRng = oSH.Cells(iRow, iCol)

oRng.FormulaR1C1 = _
Me.Controls("TextBox" & Cstr(x)).Value
Next
Next
oWB.Sheets("Kaavio1").Select
ExitHere:
On Error Resume Next
oWB.Close True

If xlNotRun The oXL.Quit

Set oRng = Nothing
Set oSheet = Nothing
Set oWB = Nothing
Set oXL = Nothing
Err.Clear
Exit Sub

xlNotRunning:
Set oXL = New Excel.Application
xlNotRun = True
Resume bmkOpenWorkbook
ErrProcessingSheet:
Msgbox "Err occurred processing worksheet" & _
"Kindly fix it" & vbCr & Err.Number & vbcr & _
Err.Description
Resume ExitHere
End Sub

Krgrds,
Perry

Mikko Rantanen via OfficeKB.com said:
Hi

I need to kill Excel process totaly.
After excel is close a Excel.exe process stays on.
How can I close excel for good ?

Regars
Mikko

I have used this macro to open workbook

Sub chart()
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim oRng As Excel.Range
Dim ExcelWasNotRunning As Boolean
Dim WorkbookToWorkOn As String

'specify the workbook to work on
WorkbookToWorkOn = "C:\Documents and Settings\All Users\Huoltoraportti\
chart.xls"

'If Excel is running, get a handle on it; otherwise start a new instance of
Excel
On Error Resume Next
Set oXL = GetObject(, "Excel.Application")

If Err Then
ExcelWasNotRunning = True
Set oXL = New Excel.Application
End If

On Error GoTo Err_Handler

'If you want Excel to be visible, you could add the line: oXL.Visible =
True here; but your code will run faster if you don't make it visible

'Open the workbook
Set oWB = oXL.Workbooks.Open(FileName:=WorkbookToWorkOn)

'Process each of the spreadsheets in the workbook
'For Each oSheet In oXL.ActiveWorkbook.Worksheets
'put guts of your code here
'get next sheet
Sheets("Taul1").Select
Range("B2").Select
ActiveCell.FormulaR1C1 = Me.TextBox1.Value
Range("C2").Select
ActiveCell.FormulaR1C1 = Me.TextBox2.Value
Range("D2").Select
ActiveCell.FormulaR1C1 = Me.TextBox3.Value
Range("E2").Select
ActiveCell.FormulaR1C1 = Me.TextBox4.Value
Range("F2").Select
ActiveCell.FormulaR1C1 = Me.TextBox5.Value
Range("G2").Select
ActiveCell.FormulaR1C1 = Me.TextBox6.Value
Range("H2").Select
ActiveCell.FormulaR1C1 = Me.TextBox7.Value
Range("I2").Select
ActiveCell.FormulaR1C1 = Me.TextBox8.Value
Range("J2").Select
ActiveCell.FormulaR1C1 = Me.TextBox9.Value
Range("K2").Select
ActiveCell.FormulaR1C1 = Me.TextBox10.Value
Range("L2").Select
ActiveCell.FormulaR1C1 = Me.TextBox11.Value
Range("M2").Select
ActiveCell.FormulaR1C1 = Me.TextBox12.Value
 
P

Perry

Oops, too fast:

- First For/Next Loop, raise iRow by one to read
For iRow = 2 to 3
- After second For/Next, raise iStart by 12 to read:
Next 'end of second loop
iStart = iStart + 12
Next 'end of first loop

Good luck ...

Krgrds,
Perry
 
M

Mikko Rantanen via OfficeKB.com

It works great after few mod's
Like setting a workbook and controls number x

Thx

Mikko
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top