Need help doing a Subtotal through Excel automation in vb.net 
Author Message
 Need help doing a Subtotal through Excel automation in vb.net

Hi, all.

I'm hoping someone out there has done this and can tell me what I'm
doing wrong.  I'm trying to add subtotals to an Excel sheet through
automation in vb.net.  I can get it to work perfectly in VB 6, but
when I try a similar call in .Net, I get the error:

"An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in
microsoft.visualbasic.dll

Additional information: Subtotal method of Range class failed"

I'm developing on a Windows 2000 machine and am using Excel 9.0.

The code I'm using looks like this:

-------
range = wks.Range("A1", GetRangeLetter(lColumnCount) & lRowCount + 1)
range.Value2 = asRowString

range2 = wks.Range("A1", GetRangeLetter(lColumnCount) & 1)
range2.BorderAround(, Excel.XlBorderWeight.xlThin,
        Excel.XlColorIndex.xlColorIndexAutomatic)

If g_iGroupBy <> -1 Then
   range.Subtotal(g_iGroupBy, Excel.XlConsolidationFunction.xlSum,
                  g_aiSubTotal, True, False,
                  Excel.XlSummaryRow.xlSummaryBelow)
End If
-------

In last line, g_iGroupBy is a valid integer and g_aiSubTotal is a
valid array of integers.  The range2 stuff is there so that Excel
knows what the column headers are.  If you remove that, you get the
standard Excel message telling you that it doesn't know what the
column headers are and to hit OK to use the top row.  If you hit OK,
you then get the same error message I posted above.

I've also tried this as a Selection instead of a Range and got the
same result.

Any ideas?

Thanks!

-Manny Wolfe
Four Rivers Software Systems, Inc.



Sun, 02 Oct 2005 23:51:31 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Excel worksheet subtotals from vb.net

2. VB - EXCEL automation error.... Help Needed

3. VB - EXCEL automation error.... Help Needed

4. VB - EXCEL automation error.... Help Needed

5. Excel Addin using vb.net Automation

6. VBA Excel Automation in VB.Net

7. Excel Automation with VB.Net

8. Excel Ole automation with VB.NET

9. Beginner Excel Automation needs help

10. Need Excel Automation help, please, please

11. VB Script in Excel....Please Help...Dead Easy if You've done it before

12. subtotals and formatting help needed

 

 
Powered by phpBB® Forum Software