Ask Your Question
3

What is a quicker method for using ADO to convert an Excel spreadsheet to an array?

asked 2023-06-07 12:03:58 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-06-07 12:10:02 +0000

david gravatar image

One quicker method for using ADO to convert an Excel spreadsheet to an array is to use the "GetRows" method. Here's an example code snippet:

Dim objConnection As Object
Dim objRecordset As Object
Dim arrData As Variant

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")

objConnection.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\path\to\excel\file.xlsx;Extended Properties=""Excel 12.0 Xml;HDR=YES;IMEX=1"" "

objRecordset.Open "SELECT * FROM [Sheet1$]", objConnection

arrData = objRecordset.GetRows()

objRecordset.Close
objConnection.Close

This code uses ADO to connect to an Excel file and select all data from the "Sheet1" worksheet. The "GetRows" method is then called on the recordset object to return all rows of data as a two-dimensional array. This array can then be used as needed in your code.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-07 12:03:58 +0000

Seen: 1 times

Last updated: Jun 07 '23