Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2005

Tip: Looking for answers? Try searching our database.

Close EXCEL.EXE process

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mikko Rantanen - 12 Apr 2005 19:57 GMT
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
Perry - 12 Apr 2005 21:26 GMT
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

> Hi
>
[quoted text clipped - 66 lines]
>     Range("M2").Select
>     ActiveCell.FormulaR1C1 = Me.TextBox12.Value

>     Range("B3").Select
>     ActiveCell.FormulaR1C1 = Me.TextBox13.Value
[quoted text clipped - 21 lines]
>     ActiveCell.FormulaR1C1 = Me.TextBox24.Value
>     Range("M4").Select

>     Sheets("Kaavio1").Select
> 'Next oSheet
[quoted text clipped - 27 lines]
> --
> Message posted via http://www.officekb.com
Perry - 12 Apr 2005 21:37 GMT
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

> Several ingredients to improve:
> Try to get the grips of below code sequence:
[quoted text clipped - 185 lines]
> > --
> > Message posted via http://www.officekb.com
Mikko Rantanen - 13 Apr 2005 15:55 GMT
It works great after few mod's
Like setting a workbook and controls number x

Thx

Mikko
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.