troubleshooting Question

Error adding worksheet to workbook

Avatar of Juan Velasquez
Juan VelasquezFlag for United States of America asked on
Microsoft ExcelVisual Basic.NET
10 Comments1 Solution706 ViewsLast Modified:
Hello,
I am trying to create function that will return a worksheet and add it to a newly created workbooks.  In the following code, I loop through a listview and populate a list object which I subsequentlly pass through Function Generate Worksheet.  When I run the code, I see the new sheet being populated but I am getting a Exception from HRESULT: 0x800A03EC error on line wb.Worksheets.Add(ws)
Dim dpl As New List(Of DatasetPair)

        'Try
        Me.Cursor = Cursors.WaitCursor
        Dim intSheetCount As Integer = 0
        For i As Integer = 0 To lvMatchedDvid.Items.Count - 1
            Dim dp As New DatasetPair
            dp.DataVersionIdOne = lvMatchedDvid.Items(i).Text.ToString
            dp.DataVersionIdTwo = lvMatchedDvid.Items(i).SubItems(1).Text.ToString
            intSheetCount += 1
            dp.SheetId = intSheetCount
            dpl.Add(dp)
        Next


        Dim wb As Excel.Workbook = Utilities.CreateWorkbook()


        For Each dp As DatasetPair In dpl
            Dim ws As New Excel.Worksheet
            ws = GenerateWorksheet(dp)
            MessageBox.Show(ws.Rows.Count.ToString)
            wb.Worksheets.Add(ws)
        Next
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 10 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros