- Excel VBA - Basics (23)
- VBA User Forms (21)
- Excel VBA - pivot tables (8)
- Excel VBA - charts (6)
- VBA - advanced (13)
- VBA - working with files (10)
- VBA - linking applications (9)
- VBA - working with Outlook (13)
- Built-in VBA functions (9)
- VBA - working with data (38)
- VBA - scraping websites (17)
- VBA - working with shapes (3)
- VBA - classes and structures (6)
VBA - WORKING WITH DATA VIDEOS▼
- Excel VBA Part 30 - Querying a Database with ADO
- Excel VBA Part 31 - Modifying Data with ADO Recordsets
- Excel VBA Part 32 - Executing SQL Commands with ADO
- Excel VBA Part 56.1 - Connect to SQL Server using ADO
- Excel VBA Part 56.2 - Get Data from SQL Server with ADO Recordsets
- Excel VBA Part 56.3 - Read and Execute SQL Query Files
- Excel VBA Part 56.4 - Return Multiple Result Sets from SQL Queries
- Excel VBA Part 56.5 - Basic ADO Commands with SQL Server
- Excel VBA Part 56.6 - ADO Commands and Parameters
- Excel VBA Part 56.7 - ADO Commands and Stored Procedures
- Excel VBA Part 58.1 - SQL for Excel Files - Basic Select Statements
- Excel VBA Part 58.2 - SQL for Excel Files - Sorting Rows in a Query
- Excel VBA Part 58.3 - SQL for Excel Files - Selecting the Top N Rows
- Excel VBA Part 58.4 - SQL for Excel Files - Selecting All or Distinct Rows
- Excel VBA Part 58.5 - SQL for Excel Files - Basic Criteria in Queries
- Excel VBA Part 58.6 - SQL for Excel Files - Text Criteria and the Like Operator
- Excel VBA Part 58.7 - SQL for Excel Files - Basic Calculated Columns
- Excel VBA Part 58.8 - SQL for Excel Files - Conditional Functions
- Excel VBA Part 58.9 - SQL for Excel Files - Nulls in Expressions
- Excel VBA Part 58.10 - SQL for Excel Files - Date Expressions
- Excel VBA Part 58.11 - SQL for Excel Files - Text Expressions
- Excel VBA Part 58.12 - SQL for Excel Files - Aggregation Functions
- Excel VBA Part 58.13 - SQL for Excel Files - Grouping Rows
- Excel VBA Part 58.14 - SQL for Excel Files - Criteria in the Having Clause
- Excel VBA Part 58.15 - SQL for Excel Files - Pivoting Data (Crosstab Queries)
- How do I pass Japanese text to a stored procedure parameter in VBA?
- How do I get data from a closed Excel file using VBA?
- How do I loop through worksheets in a closed workbook with VBA?
- How do I get data from multiple closed Excel files using VBA?
- How do I get data from multiple workbooks with one query in VBA?
- How do I loop through worksheets in multiple closed workbooks in VBA?
- How do I populate a listbox using an ADO recordset in VBA?
- How do I get the column names from an ADO recordset?
- Excel VBA - How do I get data from a CSV file using ActiveX Data Objects
- How do I add a filename to the results of an ADODB recordset?
- How do I populate an array with an ADODB recordset?
- How do I count the rows in an ADODB recordset?
- How do I find the data type of a column in an ADODB recordset?
VBA - working with data videos | How do I get data from a closed Excel file using VBA?
Posted by Andrew Gould on 08 April 2021
One way to get data from a closed Excel workbook is to open it first, but did you know that in VBA you can connect to a workbook and extract data from it without needing to open the file? This video explains how to do this using the ActiveX Data Objects library. You'll learn how to create a connection object and construct a connection string to talk to the closed Excel file. You'll also see how to create a recordset object and load a set of data into it using an SQL Select statement. As a bonus, the video shows you how to add some basic criteria to the SQL query to control which rows of data you return from the workbook.
This video has the following accompanying files:
|Get Data from Closed Workbook.xlsm||Excel workbook with macros|
Click to download a zipped copy of the above files.
Making a video bigger
You can increase the size of your video to make it fill the screen like this:
Play your video (the icons shown won't appear until you do), then click on the full screen icon which appears as shown at its bottom right-hand corner.
When you've finished viewing a video in full screen mode, just press the Esc key to return to normal view.
Improving the quality of a video
To improve the quality of a video, first click on the Settings icon:
Make sure you're playing your video so that the icons shown appear, then click on this gear icon at the bottom right-hand corner.
Choose to change the video quality:
Click on Quality as shown to bring up the submenu.
The higher the number you choose, the better will be your video quality (but the slower the connection speed):
Don't choose the HD option unless you have a fast enough connection speed to support it!
Is your Wise Owl speaking too slowly (or too quickly)? You can also use the Settings menu above to change your playback speed.
How do I get data from a closed Excel file using VBA?
I really love your videos they always have so much information in it!
I just finished watching a. m. video. My problem is the following: I have to grab data from a closed Excel-file, but the data table I need unfortunately is not positioned in row 1 - there has to remain some descriptive stuff above the very table, so I could of course grab the entire table and delete all rows which don*t belong to the datatable.
But actually I would only need a very small portion of the data, here I would only need column 3 and 4 of the datatable and only values which are bigger than a number on another sheet. I work a lot with SQL statements so it would not be a problem at all to create the statement I need, but I can't address the column names, because they are not in the first row (I would not even need the headers)
Is there a possibility to address the data using a named range instead? Or do you have another idea how to solve that problem?
Yes, you can use range names in your select statement rather than sheet names. If your range name refers to the entire data table without column headers make sure that you set the HDR extended property to NO in your connection string:
You can then use generic placeholder field names, so if you only need columns 3 and 4 you can write something like this:
"SELECT F3, F4 FROM [MyRangeName]"
I hope that helps!