none
delete excel sheets without confirming RRS feed

  • Question

  • Hi,

    I wrote a windows form application using c# and I have a excel worksheet that some new temporary sheets were added into it and I want to delete these new sheets I use the below code:

    sourceworksheet.Worksheet[3].Delete();
    sourceworksheet.Worksheet[2].Delete();
    sourceworksheet.Worksheet[1].Delete();

    but each time it want to delete the sheet it ask me to confirm deleting. is it any way that do not need this confirming and delete automatically?

    thanks.

    Saturday, January 6, 2018 1:00 PM

Answers

  • n,
    re:  "ask to confirm" not needed

    The code line in VBA to prevent all confirmation / status / warning notices from appearing is...
      Application.DisplayAlerts = False

    It is reinstated by using... Application.DisplayAlerts = True
    This should be done at every possible exit point from the code, including error handling.

    I trust you can translate the vba to C#.
    '---
    Jim Cone
    Portland, Oregon USA
    https://goo.gl/IUQUN2 (Dropbox)
    (free & commercial excel add-ins & workbooks)

    • Marked as answer by nadianaji Saturday, January 6, 2018 3:31 PM
    Saturday, January 6, 2018 3:10 PM

All replies

  • n,
    re:  "ask to confirm" not needed

    The code line in VBA to prevent all confirmation / status / warning notices from appearing is...
      Application.DisplayAlerts = False

    It is reinstated by using... Application.DisplayAlerts = True
    This should be done at every possible exit point from the code, including error handling.

    I trust you can translate the vba to C#.
    '---
    Jim Cone
    Portland, Oregon USA
    https://goo.gl/IUQUN2 (Dropbox)
    (free & commercial excel add-ins & workbooks)

    • Marked as answer by nadianaji Saturday, January 6, 2018 3:31 PM
    Saturday, January 6, 2018 3:10 PM
  • Thank you :)
    Saturday, January 6, 2018 3:31 PM