Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C#,Close Excel whitout the save as dialog

C#,Close Excel whitout the save as dialog

Scheduled Pinned Locked Moved C#
csharphelptutorialquestionlearning
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jzb
    wrote on last edited by
    #1

    In C# using excel.Application to output report.But when error happend, the excel can't close. I must write some coding for close excel.When Close excel,a save as dialog been showed.I want to not save the book,I want to close the excel only.How to do it? Can you give me a sample?

    G A D 3 Replies Last reply
    0
    • J jzb

      In C# using excel.Application to output report.But when error happend, the excel can't close. I must write some coding for close excel.When Close excel,a save as dialog been showed.I want to not save the book,I want to close the excel only.How to do it? Can you give me a sample?

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Perhaps if you undo actions back to the starting state, you can close Excel without getting the confirmation. --- b { font-weight: normal; }

      1 Reply Last reply
      0
      • J jzb

        In C# using excel.Application to output report.But when error happend, the excel can't close. I must write some coding for close excel.When Close excel,a save as dialog been showed.I want to not save the book,I want to close the excel only.How to do it? Can you give me a sample?

        A Offline
        A Offline
        AB7771
        wrote on last edited by
        #3

        Hi, u can do that by setting the variable of Excel.Workbook to true. i.e. if u have an object of Excel.Workbook called WB then just write WB.Saved = true; before closing the application or excel application. Hope that works for u Regards, Pramod

        J 1 Reply Last reply
        0
        • J jzb

          In C# using excel.Application to output report.But when error happend, the excel can't close. I must write some coding for close excel.When Close excel,a save as dialog been showed.I want to not save the book,I want to close the excel only.How to do it? Can you give me a sample?

          D Offline
          D Offline
          Drew McGhie
          wrote on last edited by
          #4

          Take a look at application.DisplayAlerts the .saved can be tricky, and there are situations where the excel doc will toggle it without you explicitly setting it. .Displayalerts suppresses ALL warnings from the excel document, but it definetely gets rid of the "do you want to save" issue.

          1 Reply Last reply
          0
          • A AB7771

            Hi, u can do that by setting the variable of Excel.Workbook to true. i.e. if u have an object of Excel.Workbook called WB then just write WB.Saved = true; before closing the application or excel application. Hope that works for u Regards, Pramod

            J Offline
            J Offline
            jzb
            wrote on last edited by
            #5

            I post the message in message boards, after this I try to use worksheet.saveas method that save to my driver, then close the worksheet. app.Workbooks[1].SaveAs(@"c:\temp.xls", Missing.Value, Missing.Value, Missing.Value,Missing.Value,Missing.Value, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Missing.Value,Missing.Value, Missing.Value, Missing.Value, Missing.Value); app.Application.Workbooks.Close(); app.Application.Quit(); app.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject (app); the work sheet been closed, but the process still in task manager until my application been closed. Why? so ,I more wrote code Process[] procs = Process.GetProcessesByName("EXCEL"); foreach (Process proc in procs) { if (!proc.CloseMainWindow()) { proc.Kill(); } } GC.Collect(); app = null; At last, the excel porcess been disappeared in task manager.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups