Message 1 of 6

Not applicable
01-18-2017
02:52 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
i have been using this function in Inventor 2010. we now upgraded to 2016 and this function does not work anymore.
I also have got Active x and Excel library references loaded.
Seems "dbconnection.Open dbconnectionstring is not working now. Is this related to inventor migrating to EXCEL API?
i am lost and any help is appreciated.
Jiten
Public Function ReadDataFromWorkbook(SourceFile, SourceRange As String) As Variant 'Public Function Since it is also used in Frm_iproperties ' requires a reference to the Microsoft ActiveX Data Objects library ' requires a reference to the Microsoft Excel 14.0 Object library ' if SourceRange is a range reference, this function can only return data from the first worksheet in SourceFile ' if SourceRange is a defined name reference, this function can return data from any worksheet in SourceFile ' SourceRange must include the range headers ' examples: ' varRecordSetData = ReadDataFromWorkbook("C:\FolderName\SourceWbName.xls", "A1:A21") ' varRecordSetData = ReadDataFromWorkbook("C:\FolderName\SourceWbName.xls", "A1:B21") ' varRecordSetData = ReadDataFromWorkbook("C:\FolderName\SourceWbName.xls", "DefinedRangeName") Dim dbConnectionString As String, dbConnection As ADODB.Connection, rs As ADODB.Recordset dbConnectionString = "DRIVER={Microsoft Excel Driver (*.xls)};ReadOnly=False;DBQ=" & SourceFile 'dbConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & SourceFile & ";Extended Properties=Excel 8.0;HDR=Yes" Set dbConnection = New ADODB.Connection MsgBox dbConnectionString On Error GoTo InvalidInput 'dbConnection.ConnectionString = dbConnectionString dbConnection.Open dbConnectionString ' open the database connection ' 32bit office clashes with 64 bit inventor here Set rs = dbConnection.Execute("[" & SourceRange & "]") On Error GoTo 0 ReadDataFromWorkbook = rs.GetRows ' returns a two dim array with all records in rs rs.Close dbConnection.Close ' close the database connection Set rs = Nothing Set dbConnection = Nothing On Error GoTo 0 Exit Function InvalidInput: MsgBox "The source file or source range is invalid!" & SourceFile & err, vbExclamation, "Get data from closed workbook" Set rs = Nothing Set dbConnection = Nothing End Function
Solved! Go to Solution.