Results 1 to 3 of 3

Thread: using Excel keeps adding books

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2003
    Posts
    193

    using Excel keeps adding books

    while creating Excel files in vb.net, all is fine, except when I want to close my PC and there are many popups to save or delete "bookx.xls". How do I prevent these blank books from being made??

    THanks,

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: using Excel keeps adding books

    Well that all depends on what your code is doing.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2003
    Posts
    193

    Re: using Excel keeps adding books

    this is basically the code I use to create it, then as I create data, I open and add sheets to it and close again.. so how do I stop it from creating ghost books???
    vb Code:
    1. Public Sub Create_Excel_File(ByVal sPath As String, ByVal sName As String)
    2.  
    3.         Dim pExcel_App As Excel.Application
    4.         Dim pExcel_Wkbook As Excel.Workbook
    5.         Dim wkbSheet As Excel.Worksheet
    6.  
    7.         Try
    8.  
    9.             pExcel_App = New Excel.Application
    10.             pExcel_Wkbook = pExcel_App.Workbooks.Add
    11.             '== add worksheet to file
    12.             wkbSheet = pExcel_Wkbook.Worksheets.Add
    13.  
    14.             Dim sOutExcelPath As String
    15.             sOutExcelPath = sPath & "\" & sName
    16.             pExcel_Wkbook.SaveAs(sOutExcelPath)
    17.  
    18.             pExcel_App.DisplayAlerts = False
    19.             pExcel_App.ActiveWorkbook.Close(SaveChanges:=True, Filename:=sOutExcelPath)
    20.             pExcel_App.Quit()
    21.  
    22.         Catch ex As Exception
    23.             MsgBox("ERROR: " & m_Current_Address & " -  Create Excel log file for - " & mDistrictName & " - " & ex.Message)
    24.         Finally
    25.             pExcel_App = Nothing
    26.             pExcel_Wkbook = Nothing
    27.             wkbSheet = Nothing
    28.         End Try
    29.  
    30.     End Sub
    Last edited by Hack; Nov 16th, 2009 at 12:04 PM. Reason: Added Highlight Tags

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