2016-10-24 107 views
0

我已经在VBScript中编写了我的代码。我在下面显示的代码的特定部分中出现错误。Microsoft VBScript运行时错误

[ActiveX Script Task] Error: User script threw an exception: Error Code: 0
Error Source= Microsoft VBScript runtime error
Error Description: Object required: 'REGroupSBUOps'

Error on Line 85

'Declaring and connection string statements 
strREGroupSBUOps ="sp_CPVarianceOpsReport6" 
Set REGroupSBUOps = oDBCon.Execute(strREGroupSBUOps) 

Dim arr() 
ReDim arr(6) 

Dim i  
arr(0) = "REGroupSBUOps" 
arr(1) = "DandBSBUOps" 
arr(2) = "Tristate/Central/EastSBUOps" 
arr(3) = "WestSBUOps" 
arr(4) = "EastSBUOps" 
arr(5) = "UKSBUOps" 
If Not (arr(i).EOF) Then ' <--error on this line 
    'followed by other statements 
+1

'arr'是一个字符串数组。字符串没有“EOF”属性。 'arr(i).EOF'应该做什么?你想用这个陈述来检查什么? –

+0

strREGroupSBUOps分配有存储过程,REGroupSBUOps是sp的结果集。检查数组和条件中的结果集名称。 –

+0

一个字符串不会奇迹般地变成一个变量,除非您使用[** Eval'](https://msdn.microsoft.com/zh-cn/library/0z5x4094.aspx),我强烈建议**。此外,这看起来像一个[X-Y问题](http://mywiki.wooledge.org/XyProblem)给我。为什么你不能简单地使用变量?请解释您尝试解决的实际问题,而不是您认为的解决方案。 –

回答

0

将代码放在你的For循环内进一分,随着存储过程的实际执行一起。将存储过程调用和数组中的名称作为参数传递给子。将所有出现的arr(i)替换为采用存储过程调用返回的记录的变量的名称(在我的示例中为rs)。

Sub ExportData(sp, name) 
    Set rs = oDBCon.Execute(sp) 

    If Not rs.EOF Then 
     sFileName1 = "\\CTSC00579895801\ime\MailReports\" & name & ".xls" 
     Set oFSOExcelFile = CreateObject("Scripting.FileSystemObject") 
     Set objExcel = CreateObject("Excel.Application") 
     objExcel.Visible = True 
     ... 
     objExcel.Quit 
     Set objExcel = Nothing 
    End If 
End Sub 

ExportData "sp_CPVarianceOpsReport 1" "Tristate_Central_EastSBUOps" 
ExportData "sp_CPVarianceOpsReport 2" "UKSBUOps" 
... 

至于进一步的优化可能需要创建Excel和FileSystemObject的对象作为全局单和公正处理的,而不是建立和一遍又一遍销毁这些实例子里面的文件。

相关问题