出现错误时转到:获取错误消息-2147024809

时间:2018-09-05 15:55:27

标签: vba excel-vba

我正在使用VBA从SAP提取数据,并根据字符串是否包含某些单词来分离状态。当发生错误时,我需要它退出循环,因为这意味着SAP接口中没有更多数据,并且它正尝试提取不存在的数据。我早先在此宏中使用了此命令,没有问题,但是现在它的行为就像on error goto命令未激活,而是弹出错误消息-2147024809。

这是第一个出错的地方goto正常工作

'Total Number in lot loop
'========================================================
For C = 0 To 20

'Exits loop when no more are found in column
On Error GoTo No_More_In_Lot

'Use Required end column since there is always data here (C does not include the current QN)
place_holder = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").getcellvalue(C, "LTRMN") ' LTRMN=Name of column in recording

Notification_Status = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").getcellvalue(C, "STTXT")

'Exits when no more data
If place_holder = "" Then
Exit For
Else
End If

'Counts Each valid complaint
If InStr(1, Notification_Status, "BIMP") Then
'Do nothing
Else

If InStr(1, Notification_Status, "CC04") Then
'do nothing
Else
Number_In_Lot = Number_In_Lot + 1
End If
End If

Next C

No_More_In_Lot:

'Places # in lot in excel
Cells(i + 2, 8) = Number_In_Lot

在那下面,我有以下代码,出现错误goto无法正常工作。

有人为我编写的代码看到任何错误吗?

'Begins separating the notification statuses
'========================================================
Number_Substantiated = 0
Number_Not_Substantiated = 0
Number_Counterfeit = 0
Number_Cancelled = 0

Current_QN = Cells(i + 2, 2)

For C = 0 To 20

'Resets the Notification Status
Notification_Status = ""

'Exits loop when no more are found in column
On Error GoTo Skip

Notification_Number = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").getcellvalue(C, "QMNUM")

If Current_QN = Notificaiton_Number Then
'Do nothing (To not include the current notification status in the report)
Else
'Pull Notification status
Notification_Status = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").getcellvalue(C, "STTXT") ' STTXT=Name of column in recording



If InStr(1, Notification_Status, "CC01") Then
Number_Substantiated = Number_Substantiated + 1
Else: End If

'Include the notifcation status in the report
If InStr(1, Notification_Status, "CC02") Then
Number_Not_Substantiated = Number_Not_Substantiated + 1
Else: End If

'Include the notifcation status in the report
If InStr(1, Notification_Status, "CC03") Then
Number_Counterfeit = Number_Counterfeit + 1
Else: End If

'Include the notifcation status in the report
If InStr(1, Notification_Status, "CC04") Then
Number_Cancelled = Number_Cancelled + 1
Else: End If


End If

Next C

Skip:

'Passes values to sheet
Cells(i + 2, 9) = Number_Substantiated
Cells(i + 2, 10) = Number_Not_Substantiated
Cells(i + 2, 11) = Number_Counterfeit
Cells(i + 2, 12) = Number_Cancelled

1 个答案:

答案 0 :(得分:0)

VB保留关键字SKIP可能有问题。

...
On Error GoTo Skip_
...
Skip_:
...

关于ScriptMan