CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2007
    Posts
    51

    Clear the contents of all cells in an Excel File???

    I have a button on my program. When clicked, I want it to open a pre-determined file and clear the content of every cell in that file. I know how to access excel files and pick a designated one and all that.

    Anyone know any code for clearing the contents of all cells?

    Thanks.

  2. #2
    Join Date
    Dec 2005
    Location
    Waterloo ON
    Posts
    545

    Re: Clear the contents of all cells in an Excel File???

    Excel.Range.ClearContents();
    The difficulty is that you have no idea how difficult it is.

    .Net 3.5/VS 2008

  3. #3
    Join Date
    Jan 2007
    Posts
    51

    Re: Clear the contents of all cells in an Excel File???

    What do I put for the range?

    I'm used to putting (1, 1) to reference cell A1. How do I specify a range that clears everything on the spreadsheet?

    Thanks.

  4. #4
    Join Date
    Dec 2003
    Location
    Northern Ireland
    Posts
    1,362

    Re: Clear the contents of all cells in an Excel File???

    Greetings fellow irishman

    For a range, enter 'A1:IV65536' you can't have anything outside that. Although there is probably some handy function to get a range of everything.
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook


    0100 1101 0110 1001 0110 0011 0110 1000 0110 0001 0110 0101 0110 1100 0010 0000 0100 0101 0110 1100 0110 1100 0110 0101 0111 0010

  5. #5
    Join Date
    Dec 2002
    Posts
    305

    Re: Clear the contents of all cells in an Excel File???

    oops! Here is the correct version!!!

    xl.displayalerts=false
    xls.cells.select
    xls.delete

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

Featured