I am trying to perform a UNION on two different worksheets located in two different workbooks. I can extract data from one worksheet at a time and get it into a recordset object, but two at the same time is just not working. This is an automated Excel tool.
I can't use Access to perform the Union as that is against my requirements. I can pull each table and loop through but if I can just Union (and later Inner Join) the two tables with one go, it would save a lot of looping.
here is the connection string I'm using:
'XXXX - Replaced with Path to source file, YYYY - Replaced with Excel version (Cur 8.0 or 12.0)
Global Const EXCELCONNSTRING = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=XXXX;Extended Properties='excel YYYY;HDR=YES';Persist Security Info=False;"
The code goes:
Dim myRCD As New Recordset
Dim myConn As New Connection
Dim strSQL As String
'Open Connection
myConn.Open GetDBConnectionString(2, "C:\PartData.xlsx")
'Generate SQL
strSQL = SELECT * From [Purchased Parts$] UNION SELECT * From [Parts Data$] IN 'C:\PurchaseParts.xlsm' 'Excel 12.0'
'Get Database
myRCD.Open strSQL, myConn, adOpenForwardOnly, adLockOptimistic
Upon hitting the last line I get the following error:
Run-time error '-2147467259 (80004005)':
Unrecognized database format 'C:\PartData.xlsx'.
Thanks all!
Jared Streger