Hi,
I am trying to get all the ranges from an Excel document.
One of the ranges has the scope of the whole workbook, the other one of a specific worksheet.
When I call the objWorkbook.Worksheets.GetNamedRanges() it returns one range (the whole workbook scoped one), but not the specific one.
So I tried to call objWorkbook.Worksheets(n).Cells.Ranges.Count, but for both the worksheets it return 0.
Am I quering the incorrect collection to get the ranges for a specific worksheet?
I have include my test excel as an example, and this is the simple code to query if the range name existst:
Dim objWorkBook As Workbook = Nothing
objWorkBook = New Workbook(IO.Path.Combine(InputPath, strInputFileName))
Dim objWorksheet As Worksheet = objWorkBook.Worksheets(strWorksheetName)<span style="color:blue;">If</span> objWorksheet <span style="color:blue;">Is</span> <span style="color:blue;">Nothing</span> <span style="color:blue;">Then</span> <span style="color:blue;">Throw</span> <span style="color:blue;">New</span> <span style="color:#2b91af;">Exception</span>(<span style="color:blue;">String</span>.Format(<span style="color:#a31515;">"Worksheet with name {0} could not be found"</span>, strWorksheetName)) <span style="color:blue;">End</span> <span style="color:blue;">If</span> <span style="color:blue;">Dim</span> objRanges <span style="color:blue;">As</span> <span style="color:#2b91af;">RangeCollection</span> = objWorksheet.Cells.Ranges() <span style="color:blue;">For</span> <span style="color:blue;">Each</span> objRange <span style="color:blue;">As</span> <span style="color:#2b91af;">Range</span> <span style="color:blue;">In</span> objRanges <span style="color:blue;">If</span> objRange.Name = strRangeName <span style="color:blue;">Then</span> <span style="color:blue;">Return</span> <span style="color:blue;">True</span> <span style="color:blue;">End</span> <span style="color:blue;">If</span> <span style="color:blue;">Next</span> <span style="color:blue;">Return</span> <span style="color:blue;">False</span></pre></div><div><div><br></div><div>Kind regards,</div><div><br></div><div>Sjoerd van Loon</div></div>