Operation is not allowed_error message大家好,
我在尝试执行脚本时遇到错误。这是在尝试通过ADODB连接打开和读取excel时出现。错误是由于"当对象关闭时不允许操作。","来自外部数据库驱动程序的错误(1)。"
错误消息 - "关闭对象时不允许操作"
代码:
Public Function GetData(strDatabaseType, strfileName_SQL, strSheetNameDBName,intMode)
On Error Resume Next
Const adOpenStatic = 3
Const adLockOptimistic = 3
Set objConn = CreateObject("ADODB.Connection")
Set objGetData = CreateObject("ADODB.Recordset")
Set objCom = CreateObject("ADODB.Command")
Select Case strDatabaseType
Case "Excel"
If intMode = 0 Then
objConn.Open "Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=" & strfileName_SQL & ";DefaultDir=C:\;"
objGetData.Open "Select * from [" & strSheetNameDBName & "$]", objConn
Set GetData = objGetData
ElseIf intMode = 1 Then
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strfileName_SQL & ";Extended Properties=""Excel 8.0;HDR=Yes;"";"
objGetData.Open "Select * from [" & strSheetNameDBName & "$]", objConn, adOpenStatic, adLockOptimistic
Set GetData = objGetData
End If
End function
从上面的代码行开始,当intMode变为1时,错误抛出-objconn.open行