itterate through Custom Views Excel object

vinnie881

Well-known member
Joined
Sep 3, 2006
Messages
152
Programming Experience
3-5
I need to interact with Excel via the Microsoft Excel 9.0 Oject Library.

My issue is I can not itterate through custom views I have created in excel for the life of me

VB.NET:
Imports EXCEL

Private sub test()
       Dim ExcelApp As Excel.Application
        ExcelApp = New Excel.Application
        ExcelApp.Visible = True
        Dim wb As Excel.Workbook = ExcelApp.Workbooks.Open("C:\test.xls")
       

         'I can see the count of my custom views by doing
        
         debug.write(wb.CustomViews.Count())

        'I can get my custom view by doing

        Dim cv As Excel.CustomView = wb.CustomViews.Item("MyView1")

        'My issue is I need to itterate through the custom view collection for each view to get the name.
        'I can not hard code each one in.  The below code does not work:

        Dim c As CustomView
        For Each c In wb.CustomViews
            Debug.Write(c.Name())
        Next

        'Any Sugestions?
end sub
 
The Microsoft doco on the CustomViews.Items method say you can access items by name or index. Either they are lying or i'm doing something wrong. After a bit of thinking I guessed they were using a 1 based index instead of 0. Tried it and it worked.

I hate not being able to solve something. No COM Library gets the better of me. :)

http://msdn2.microsoft.com/de-de/library/microsoft.office.interop.excel.customviews.item(VS.80).aspx

Parameters
ViewName
Required Object. The name or index number for the object.
 
Back
Top