CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2009
    Posts
    2

    Excel - Referencing a named range

    Hi folks, I'm tearing my hair out over this one and any help would be greatly appreciated.

    I'm trying to reference a named range in my worksheet, but of the two methods that I've found, neither work.

    If I use this:

    dataRange = Program.application.Names.Application.Names("name of range").RefersToRange;

    I receive the following error:
    Non-invocable member 'Microsoft.Office.Interop.Excel._Application.Names' cannot be used like a method.


    If I try to index it, as some have suggested, like this:

    dataRange = Program.application.Names.Application.Names["name of range"].RefersToRange;

    I recieve this error:
    Cannot apply indexing with [] to an expression of type 'Microsoft.Office.Interop.Excel.Names'


    Can anyone tell me what I'm doing wrong?

  2. #2
    Join Date
    Oct 2009
    Posts
    2

    Re: Excel - Referencing a named range

    I'm sorry, the line that I posed up there isn't the correct line. I was trying random garbage in my frustration.

    Here are the two alternatives that I've tried:

    dataRange = c_application.ActiveWorkbook.Names["name of range"].RefersToRange;

    dataRange = c_application.ActiveWorkbook.Names("name of range").RefersToRange;

  3. #3
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Re: Excel - Referencing a named range

    Take a look at the Gembox.Spreadsheet Samples programme. You can download it from their site for free. It gives you some examples of how to do many things in Excel using C#. http://www.gemboxsoftware.com/

    Its on this page http://www.gemboxsoftware.com/GBSpreadsheet.htm in the paragraph headed:

    Features
    (>) Launch the GemBox.Spreadsheet Sample Explorer

    Download it and install it, very easy to use and view the code.
    Last edited by rliq; October 5th, 2009 at 06:15 PM.
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

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