Excel自动化错误
问题描述:
我得到一个“自动化错误”就行rstLgn_details.Open SqlCmd
Excel自动化错误
这是代码。
Call ConnectSS_Param(ThisWorkbook.FullName)
Set rstLgn_details = CreateObject("ADODB.Recordset")
Set SqlCmd = CreateObject("ADODB.Command")
Set SqlparamUserID = SqlCmd.CreateParameter("@UserID", 129, 1, 52, txtUsername.Value)
StrSql = "SELECT Capabilityname,SLAA_EID FORM $Login_Details WHERE [email protected]"
SqlCmd.ActiveConnection = conndb
SqlCmd.CommandText = StrSql
SqlCmd.Parameters.Append SqlparamUserID
rstLgn_details.Open SqlCmd
If rstLgn_details.RecordCount > 0 Then
UserName = rstLgn_details(1)
CapHlded = rstLgn_details(0)
ThisWorkbook.Sheets("Serach").Select
Else
MsgBox "Sorry You are Not Authorized for this..... ", vbInformation + vbOKOnly, "Invaild User"
End If
答
当您重新连接到Excel工作簿时,原始文件关闭,并且设置为原始文件的所有引用不再有效。当您尝试使用其中一个无效引用时,您将获得Automation Error
。
这里是Automation Error Using Excel Object in Visual Basic Procedure
的使出,当您在Visual Basic程序访问一个Microsoft Excel OLE自动化对象,而Microsoft Excel中关闭,则会出现此问题。例如,如果您使用CreateObject函数创建工作表对象的引用,并且在过程中使用GetObject函数创建另一个Microsoft Excel对象的引用,那么如果您随后设置了Microsoft Excel工作表对象(Excel.Sheet)等于没有,如果您尝试访问其他对象,则会收到OLE自动化错误消息。
对于一件事你有FORM而不是'FROM'。 –