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

    [RESOLVED] [VS2010] Excel Worksheet Issues

    Hey guys,

    So I've a program that is exporting an excel document. I have two different issues with this:
    1. I need to add a worksheet
    2. I need to delete the default worksheets (I have some code for this one but it returns a COM error)


    Can somebody please point me in the right direction with this? I've been searching the net but the way the person that started my application is different from the ways that everybody else seems to be doing it.

    Thanks in advance.

  2. #2
    Join Date
    Jul 2012
    Posts
    46

    Re: [VS2010] Excel Worksheet Issues

    Quote Originally Posted by S_John View Post
    1. I need to add a worksheet
    I figured this one out by fooling around with my application some more. --Palm to forehead--

  3. #3
    Join Date
    Jul 2012
    Posts
    46

    Re: [VS2010] Excel Worksheet Issues

    oWkBk.Sheets("Sheet1").Delete()

    This is the error I receive when I try to run the code line above:
    "COM object that has been separated from its underlying RCW cannot be used."

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: [VS2010] Excel Worksheet Issues

    Are you disposing excel's objects before the call to delete the sheet?

  5. #5
    Join Date
    Jul 2012
    Posts
    46

    Re: [VS2010] Excel Worksheet Issues

    Dear Hannes,

    I would like a clone of you to be peering over my shoulder so that you could smack me in the back of the head every time I make a stupid mistake.

    I was releasing the objects before my call to delete the sheet (the code is a bit messy...I should probably clean it up so I don't waste others' time)

    Thanks again for saving my hide,

    Seth

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