Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How do I connect to a named range in Excel from Visual Basic?

0
Posted

How do I connect to a named range in Excel from Visual Basic?

0

First we need to add a reference to the Microsoft Excel Office library. Do this by: Then by selecting the Microsoft Excel Object library. Note 9.0 is for Excel 2000, and 10.0 is for Excel XP. Once we have added the Excel object library reference to our project, then we can refer to it in our application. Let’s say we have a spreadsheet named “Demo.xls”, located at “C:\Demo.xls”. It contains the named range “Data”. Then we add the following code in the VB project: ‘ Declarations Public appExcel As Excel.Application Public wbDemo As Workbook ‘ Load Excel Application Set appExcel = CreateObject(“Excel.Application”) ‘ Load Workbook Set wbDemo = appExcel.Workbooks.Open(C:\Demo.xls”) ‘ Map the named range into XYChart XYChart.ChartData = wbDemo.Names(“Data”).RefersToRange.Value XYChart.Refresh ‘ Close the Workbook and end Excel wbDemo.Close appExcel.Quit Set appExcel = Nothing ‘ Free unused memory Note that you must ensure that the dimensions of the named range and XYChart are consistent. Sp

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123