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. Interop: Anyone know how to save an Excel workbook without the "Do you want to save" popup?

Interop: Anyone know how to save an Excel workbook without the "Do you want to save" popup?

Scheduled Pinned Locked Moved C#
comtutorialquestion
4 Posts 2 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.
  • A Offline
    A Offline
    Alaric_
    wrote on last edited by
    #1

    Does anyone know the incantation to save an excel workbook without having the "Do you want to save" popup appearing? I cannot have the confirmation appear because the alterations I am making to the file need to be seamless.

    Application excel = new Application();
    Workbook workbook = excel.Workbooks.Open(Filename);
    var sheet = workbook.ActiveSheet;
    Range column = sheet.Range["B1"].EntireColumn;
    column.Insert(XlInsertShiftDirection.xlShiftToRight);
    workbook.Save();
    //workbook.SaveAs(Filename);
    workbook.Close();
    Marshal.ReleaseComObject(workbook);
    Marshal.ReleaseComObject(excel);

    This will save the file, but the popup is not suppressed.

    "I need build Skynet. Plz send code"

    N A 2 Replies Last reply
    0
    • A Alaric_

      Does anyone know the incantation to save an excel workbook without having the "Do you want to save" popup appearing? I cannot have the confirmation appear because the alterations I am making to the file need to be seamless.

      Application excel = new Application();
      Workbook workbook = excel.Workbooks.Open(Filename);
      var sheet = workbook.ActiveSheet;
      Range column = sheet.Range["B1"].EntireColumn;
      column.Insert(XlInsertShiftDirection.xlShiftToRight);
      workbook.Save();
      //workbook.SaveAs(Filename);
      workbook.Close();
      Marshal.ReleaseComObject(workbook);
      Marshal.ReleaseComObject(excel);

      This will save the file, but the popup is not suppressed.

      "I need build Skynet. Plz send code"

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      Try setting DisplayAlerts=false http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel._application.displayalerts.aspx[^]


      No comment

      A 1 Reply Last reply
      0
      • A Alaric_

        Does anyone know the incantation to save an excel workbook without having the "Do you want to save" popup appearing? I cannot have the confirmation appear because the alterations I am making to the file need to be seamless.

        Application excel = new Application();
        Workbook workbook = excel.Workbooks.Open(Filename);
        var sheet = workbook.ActiveSheet;
        Range column = sheet.Range["B1"].EntireColumn;
        column.Insert(XlInsertShiftDirection.xlShiftToRight);
        workbook.Save();
        //workbook.SaveAs(Filename);
        workbook.Close();
        Marshal.ReleaseComObject(workbook);
        Marshal.ReleaseComObject(excel);

        This will save the file, but the popup is not suppressed.

        "I need build Skynet. Plz send code"

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

        Hurray! I get to answer my own question lol

        excel.DisplayAlerts = false;

        fixed.

        "I need build Skynet. Plz send code"

        1 Reply Last reply
        0
        • N Not Active

          Try setting DisplayAlerts=false http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel._application.displayalerts.aspx[^]


          No comment

          A Offline
          A Offline
          Alaric_
          wrote on last edited by
          #4

          Thanks, Mark.

          "I need build Skynet. Plz send code"

          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