I want to read an excel sheet and display the contents with vbscript. The ACE OLEDB providor has to be used (please don’t ask, I know this is end of life and not sustainable etc, but I cannot change this right now), so I installed the Microsoft Access Database Engine 2016 Redistributable (accessdatabaseengine_X64.exe). Furtermore I have Microsoft 365 Apps for Enterprise installed (x64) on my laptop with Windows 11.
I created an excel file with 1 sheet, 2 columns and a few rows of content like this:
saved it as test.xslx. Then created a file called test.vbs in the same directory with this content:
Option Explicit
Dim fso : set fso = CreateObject("Scripting.FileSystemObject")
Dim g_sCfg : g_sCfg = fso.GetFolder(fso.GetAbsolutePathName(".")) & "" & "test.xlsx"
Dim connectString : connectString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & g_sCfg & ";Extended Properties=""Excel 12.0;HDR=Yes;"";"
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
Dim objConnection, objRecordset
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConnection.Open connectString
' wscript.sleep 1000
objRecordset.CursorLocation = adUseClient
On Error Resume Next
objRecordset.Open "SELECT * FROM namenblok" , objConnection, adOpenStatic, adLockOptimistic ' namenblok is een op naam gedefinieerde blok aan cellen
If Err.Number <> 0 Then
'error handling:
WScript.Echo Err.Number & " Srce: " & Err.Source & " Desc: " & Err.Description
Err.Clear
End If
Do While Not(objRecordset.EOF)
wscript.echo objRecordset("id") & " " & objRecordset("naam")
objRecordset.MoveNext
Loop
objRecordset.Close
objConnection.Close
When I run this (eg, double click it), it nicely displays all rows from the excel sheet one by one like this:
But when changed to a .hta (html application) and adding only the script parts like this:
<script language="VBScript">
Option Explicit
…
…
objConnection.Close
</script>
it says when ran: “Provider cannot be not found. It may be not properly installed.” and points to line 15 with: objConnection.Open connectString:
I probably have to adjust the html part because of changed html restrictions, but cannot find how and what exactly. Any help would be appreciated!