Results 1 to 4 of 4

Thread: Can't Stop Excel.exe

  1. #1

    Thread Starter
    Addicted Member MikeHost's Avatar
    Join Date
    Nov 2000
    Location
    Missouri
    Posts
    175

    Can't Stop Excel.exe

    I've got a simple COM that creates an excel spreadsheet. The problem is that each time I execute an asp page that calls it, it starts a process excel.exe. The process continues after to COM is distroyed... it even appears to be getting CPU time for a while. Here is the code:

    Public Function CreateWorkbook(oRS As Object) As Boolean
    Dim goExcel As Excel.Application
    Dim oField As ADODB.Field
    Dim I As Integer
    Dim FName As String

    On Error GoTo ExcelError

    Set goExcel = New Excel.Application

    goExcel.Workbooks.Add
    With goExcel.ActiveSheet
    I = 1
    For Each oField In oRS.Fields
    .Cells(1, I).Value = oField.Name
    I = I + 1
    Next
    I = I - 1
    End With

    goExcel.Range("A2").CopyFromRecordset oRS
    goExcel.Range(Cells(1, 1), Cells(1, I)).Select
    goExcel.Selection.Font.Bold = True
    goExcel.ActiveSheet.Columns("a:z").AutoFit

    goExcel.ActiveWorkbook.SaveAs mvarSaveFileName
    goExcel.ActiveWorkbook.Close

    goExcel.Quit


    Set goExcel = Nothing

    CreateWorkbook = True

    Exit Function

    ExcelError:

    mvarErrormsg = Err.Description
    CreateWorkbook = False

    End Function

    Any help would be appreciated!
    <<<<>>>>

  2. #2

    Thread Starter
    Addicted Member MikeHost's Avatar
    Join Date
    Nov 2000
    Location
    Missouri
    Posts
    175
    If I call the COM from a VB6 app, the excel.exe process will close after I close the application.
    <<<<>>>>

  3. #3
    Lively Member
    Join Date
    Aug 2002
    Posts
    126
    put that code in a module:

    Option Explicit

    Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    'Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Public Declare Function FindWindow& Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String)
    Public Declare Function IsIconic& Lib "user32" (ByVal hwnd As Long)
    Public Declare Function SendMessage& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
    Public Declare Function ShowWindow& Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long)
    Public Declare Function SetForegroundWindow& Lib "user32" (ByVal hwnd As Long)

    Public Const WM_CLOSE = &H10
    Public Const SW_SHOWNORMAL& = 1
    Public Const WM_USER = 1024
    Public Const WM_ACTIVATE = &H6
    Public Const WM_ACTIVATEAPP = &H1C

    Function fIsAppRunning(ByVal strAppName As String, _
    Optional fActivate As Boolean) As Boolean

    Dim lngH As Long, strClassName As String
    Dim lngX As Long, lngTmp As Long, x As Long

    On Local Error GoTo fIsAppRunning_Err

    fIsAppRunning = False

    Select Case LCase$(strAppName)
    Case "excel": strClassName = "XLMain"
    Case "word": strClassName = "OpusApp"
    Case "access": strClassName = "OMain"
    Case "powerpoint95": strClassName = "PP7FrameClass"
    Case "powerpoint97": strClassName = "PP97FrameClass"
    Case "notepad": strClassName = "NOTEPAD"
    Case "paintbrush": strClassName = "pbParent"
    Case "wordpad": strClassName = "WordPadClass"
    Case Else: strClassName = ""
    End Select

    If strClassName = "" Then
    lngH = FindWindow(vbNullString, strAppName)
    Else
    lngH = FindWindow(strClassName, vbNullString)
    End If
    x = PostMessage(lngH, WM_CLOSE, 0, 0&)
    If lngH <> 0 Then
    SendMessage lngH, WM_USER + 18, 0, 0
    lngX = IsIconic(lngH)
    'If lngX <> 0 Then
    lngTmp = ShowWindow(lngH, SW_SHOWNORMAL)
    'End If
    If fActivate Then
    lngTmp = SetForegroundWindow(lngH)
    End If
    fIsAppRunning = True
    End If



    fIsAppRunning_Exit:
    Exit Function
    fIsAppRunning_Err:
    fIsAppRunning = False
    Resume fIsAppRunning_Exit
    End Function



    and then u can call the function from client:
    Private Sub Command1_Click()

    Dim blnFlag As Boolean

    blnFlag = fIsAppRunning("excel", False)

    End Sub

  4. #4
    Hyperactive Member Libero's Avatar
    Join Date
    Jun 2000
    Location
    Swedish viking
    Posts
    460
    Yesterday i solved my prob that was the same as yours. My code was like this
    VB Code:
    1. Range(Selection, Selection.End(xlDown)).Select
    2.  
    3. ' I changed it to:
    4.  
    5. Objexcel.Range(Objexcel.Selection, Objexcel.Selection.End(xlDown)).Select

    So your problem might be:

    VB Code:
    1. goExcel.Range("A2").CopyFromRecordset oRS
    2. goExcel.Range(Cells(1, 1), Cells(1, I)).Select  ' This code
    3. goExcel.Selection.Font.Bold = True
    4. goExcel.ActiveSheet.Columns("a:z").AutoFit
    5.  
    6. ' Try
    7.  
    8. goExcel.Range(goExcel.Cells(1, 1), goExcel.Cells(1, I)).

    Please let us know if this was successfull.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width