+ Reply to Thread
Results 1 to 3 of 3

help!kill process excel.exe

  1. #1
    Registered User
    Join Date
    08-03-2006
    Posts
    1

    help!kill process excel.exe

    i have created a excel workbook in vb,below are the codes:

    private sub report ()
    Dim sfilename As String
    Dim spath As String
    Dim dtecurrent As Date
    Dim msexcel As Object
    dtecurrent = Now
    Set msexcel = CreateObject("Excel.Application")

    With msexcel
    .Visible = False
    .Workbooks.Open "d:\DYNAMICS\PDB\RPT.xls", , False
    End With

    With msexcel.Application
    .ActiveWorkbook.ActiveSheet.Select
    .Cells(2, 1) = Time
    .Cells(2, 2) = Date
    End With
    sfilename = Format(dtecurrent, "mmddyyyy HHMMSS") & ".xls"

    spath = System.BasePath & "\htrdata\" & sfilename

    msexcel.ActiveWorkbook.SaveAs spath 'Saves the file with the path

    msexcel.Visible = True

    Set msexcel = Nothing
    end sub

    *********
    in the program i call the function period,because the excel run in background,so the problem is every time it will add a windows process, how can i close the process in the function?

  2. #2

    Re: help!kill process excel.exe

    Hi,

    If you are running this function from within Excel, there is no need of
    using CreateObject. Instead use Workbooks.open(FileName)

    If you want to avoid this book getting focus on open put the followoing
    line above the open method:

    Application.ScreenUpdating=false

    Pramathesh


    xz739 wrote:
    > i have created a excel workbook in vb,below are the codes:
    >
    > private sub report ()
    > Dim sfilename As String
    > Dim spath As String
    > Dim dtecurrent As Date
    > Dim msexcel As Object
    > dtecurrent = Now
    > Set msexcel = CreateObject("Excel.Application")
    >
    > With msexcel
    > .Visible = False
    > .Workbooks.Open "d:\DYNAMICS\PDB\RPT.xls", , False
    > End With
    >
    > With msexcel.Application
    > .ActiveWorkbook.ActiveSheet.Select
    > .Cells(2, 1) = Time
    > .Cells(2, 2) = Date
    > End With
    > sfilename = Format(dtecurrent, "mmddyyyy HHMMSS") & ".xls"
    >
    > spath = System.BasePath & "\htrdata\" & sfilename
    >
    > msexcel.ActiveWorkbook.SaveAs spath 'Saves the file with the path
    >
    > msexcel.Visible = True
    >
    > Set msexcel = Nothing
    > end sub
    > *********
    > in the program i call the function period,because the excel run in
    > background,so the problem is every time it will add a windows process,
    > how can i close the process in the function?
    >
    >
    > --
    > xz739
    > ------------------------------------------------------------------------
    > xz739's Profile: http://www.excelforum.com/member.php...o&userid=37053
    > View this thread: http://www.excelforum.com/showthread...hreadid=567780



  3. #3
    NickHK
    Guest

    Re: help!kill process excel.exe

    Assuming you are using VB5/6:
    - It is easier to start using early binding (setting a reference) and
    declaring your object as the correct type. eg.
    Dim MSExcel As Excel.Application
    Dim WB As Excel.Workbook
    etc
    That way you get Intellisense to help you with syntx

    - Here, do you mean that excel or your VB form is not visible ?
    With msexcel
    Visible = False
    Workbooks.Open "d:\DYNAMICS\PDB\RPT.xls", , False
    End With
    MSExcel.Visible<>Me.Visible=False

    - Here MSExcel IS the application, so just use MSExcel
    With msexcel.Application

    - Make sure you alway use fully qualified object:
    e.g.
    Dim WB As Excel.Workbook
    Set WB=Workbooks.Open ("d:\DYNAMICS\PDB\RPT.xls", , False)
    With WB
    With .Worksheets(1)
    .Cells(2,1).Value=
    .Cells(2,2).Value=
    End with
    .SaveAs Filename
    End With

    - It's not closing because you are not tell Excel to close. You need to add
    WB.Close
    Set WB=Nothing
    MSExcel.Quit
    Set MSExcel=nothing

    As it seems that you are using VB.Net, I can't tell if the syntax is
    correct, but the logic is.

    NickHK

    "xz739" <[email protected]> wrote in
    message news:[email protected]...
    >
    > i have created a excel workbook in vb,below are the codes:
    >
    > private sub report ()
    > Dim sfilename As String
    > Dim spath As String
    > Dim dtecurrent As Date
    > Dim msexcel As Object
    > dtecurrent = Now
    > Set msexcel = CreateObject("Excel.Application")
    >
    > With msexcel
    > Visible = False
    > Workbooks.Open "d:\DYNAMICS\PDB\RPT.xls", , False
    > End With
    >
    > With msexcel.Application
    > ActiveWorkbook.ActiveSheet.Select
    > Cells(2, 1) = Time
    > Cells(2, 2) = Date
    > End With
    > sfilename = Format(dtecurrent, "mmddyyyy HHMMSS") & ".xls"
    >
    > spath = System.BasePath & "\htrdata\" & sfilename
    >
    > msexcel.ActiveWorkbook.SaveAs spath 'Saves the file with the path
    >
    > msexcel.Visible = True
    >
    > Set msexcel = Nothing
    > end sub
    > *********
    > in the program i call the function period,because the excel run in
    > background,so the problem is every time it will add a windows process,
    > how can i close the process in the function?
    >
    >
    > --
    > xz739
    > ------------------------------------------------------------------------
    > xz739's Profile:

    http://www.excelforum.com/member.php...o&userid=37053
    > View this thread: http://www.excelforum.com/showthread...hreadid=567780
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1