Get Data form closed Excel workbook with ADODB

Kappes105

New Member
Joined
Sep 15, 2021
Messages
11
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone

I am trying to read data from a closed workbook. I would like to use dynamic range names. I define these with the name manager.

My problem is as follows:

If I set the name to fixed =Sheet1!$A$1:$A$3, then access to the datarange works perfectly.

However, if I create the name dynamically =OFFSET(ShLookup!$B$1,0,0,COUNTA(shLookup!$B:$B),1), I get the error message that the object “Range name” cannot be found.

My select looks like this
' SQL query to retrieve the named range
strSQL = “select * from [” & NamedRange & “]”

Does anyone have any ideas on how I can make the access so that the dynamically named range is used?

Translated with DeepL.com (free version)
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Getting data using ADO won't let you reference dynamic named ranges. It is best just to grab a huge section of the data and parse it in the receiving workbook. So if your table is dynamically range A1:J1001, then simply get all the data from A1:X1000000. Then use some code to figure out the column count and row count after you paste it.

You could also created a named range in your source file that encompasses more rows than you'll ever use.
 
Upvote 0

Forum statistics

Threads
1,224,884
Messages
6,181,552
Members
453,052
Latest member
ezzat

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top