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
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