none
Error Message - while storing multiple ranges into arrays..... Please help RRS feed

  • Question

  • Hi,

    I created a program in VS 2010 for VSTO excel to update the selected ranges to PowerPoint 2007 charts.

    To store the selected ranges into arrays, below is the part of the code.

    Dim oWS As Excel.Workbook
    Dim SelAreas() As Excel.Range

                '  Store the areas as separate Range objects
                oWS = Me.Application.ActiveWorkbook
                NumAreas = oWS.Application.Selection.Areas.Count
                Debug.Print(oWS.Name.ToString())

                ReDim SelAreas(0 To NumAreas - 1)

                For i = 0 To NumAreas - 1
                        SelAreas(i) = oWS.Application.Selection.Areas(i) 'Error in this line
                Next

    The error message is as follows:

    System.Runtime.InteropServices.COMException(0x800A03EC): Exception from HRESULT: 0x800A03EC

    at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolen[] CopyBack)

    at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[]  Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolen[] CopyBack)


    For nearly two days, I googled and tried to rectify this. But couldn't understand it.

    Please help me.

    Thanks,
    balumail75.




    Monday, May 27, 2013 6:15 AM

Answers

  • SelAreas is your own array which starts from 0. Your problem is with this line:

    oWS.Application.Selection.Areas(i) - this is an office array and can only be indexed from 1

    • Marked as answer by balumail Monday, May 27, 2013 10:31 AM
    Monday, May 27, 2013 10:00 AM

All replies

  • in office API collections are indexed from 1 to Count, opposite to C style.
    Monday, May 27, 2013 7:23 AM
  • Should I start the i - index from 1?

    In vb.net, the array starts from 0?

    • Edited by balumail Monday, May 27, 2013 7:44 AM
    Monday, May 27, 2013 7:43 AM
  • language does not matter, what matters is where array comes from - this one comes from office libraries and all arrays that originate from that world start with 1.
    Monday, May 27, 2013 8:13 AM
  • Hi Damian,

    if I change to:

                ReDim SelAreas(1 To NumAreas) 'Error in this line

                For i = 1 To NumAreas
                        SelAreas(i) = oWS.Application.Selection.Areas(i)
                Next

    Error message is:

    Array lower bounds can be only '0'.

    Is there any way to change the base option of array to 1?

    Thanks for your reply.

    Regards,
    Balumail75.


    • Edited by balumail Monday, May 27, 2013 9:32 AM
    Monday, May 27, 2013 9:14 AM
  • SelAreas is your own array which starts from 0. Your problem is with this line:

    oWS.Application.Selection.Areas(i) - this is an office array and can only be indexed from 1

    • Marked as answer by balumail Monday, May 27, 2013 10:31 AM
    Monday, May 27, 2013 10:00 AM
  • Thanks for you gr8 help and for the usefull information. (Office APIs starts from index 1)
    Monday, May 27, 2013 10:31 AM