为什么我得到一个没有Do'或者'其次没有For'错误?

时间:2014-05-15 19:28:18

标签: loops for-loop

我一直在研究这个问题,而对于我的生活,我无法弄清楚我错过了什么。我错过了'Next'或'Do',但看起来我已经拥有了它。

感谢任何帮助。

      Do
            ufCCB.Show
            If Continue = True Then
                iret = iim1.iimInit
                iret = iim1.iimSet("UNAME", UN)
                iret = iim1.iimSet("PWORD", PW)
                iret = iim1.iimPlay("VH-ccb-logIn-User")
                If iret = 1 Then
                    retry = False
                Else
                    TryCount = TryCount + 1
                    iret = iim1.iimExit
                End If
                If TryCount = 2 Then
                    retry = False
                    MsgBox "Alas my friend, you have inputted the wrong password twice. Please try again."
                    Continue = False
                End If
            Else
                retry = False
            End If
        Loop Until retry = False


'            Set iim1 = CreateObject("imacros")
'            iret = iim1.iimInit
'            iret = iim1.iimSet("UNAME", UN)
'            iret = iim1.iimSet("PWORD", PW)
'            iret = iim1.iimPlay("VH-ccb-logIn-User")
            TotalFailures = 0
            iret = iim1.iimPlay("VH-CCB-Reset")
            'Application.Wait (Now() + "00:00:01")


'Step AD: Insert Last Start Time/Date
        ThisWorkbook.Sheets("Control").Cells(2, 2) = Now()
        ThisWorkbook.ActiveSheet.Select

        'Continue is set from the Login to confirm that CC&B is open and ready
        If Continue Then
            iret = iim1.iimPlay("VH-CCB-reset")
        Else: GoTo IThinkWereDoneHere
        End If

        Do
    TryCount = 0
AssignCurrentVars:
        'Restart the browser if too many errors occur.
        If TotalFailures = 3 Then
                iret = iim1.iimExit

        End If

For Each ws In Workbooks("ElecOpsCSD_FollowUp_iMacro.xlsm").Worksheets
ws.Select
If ws.Name <> "Control" And ws.Name <> "OutputArchive" And ws.Name <> "CC&B_Process" Then
ws.Activate
If ThisWorkbook.ActiveSheet.Cells(RowCntr, 1).Value <> "" Then
    If ThisWorkbook.ActiveSheet.Cells(RowCntr, 12).Value = "" Then
        Do
                       FieldOrderID = ThisWorkbook.ActiveSheet.Cells(RowCntr, 1).Text
                                If Len(FieldOrderID) < 3 Then
                                    FieldOrderID = ""
                                    TryCount = TryCount + 1
                                    If TryCount = 3 Then
                                        GoTo IThinkWereDoneHere
                                    End If
                                End If
                       FO_Status = ThisWorkbook.ActiveSheet.Cells(RowCntr, 2).Text
                       FO_Comments = ThisWorkbook.ActiveSheet.Cells(RowCntr, 3).Text
                       Badge_Number = ThisWorkbook.ActiveSheet.Cells(RowCntr, 4).Text
                       Device_Type = ThisWorkbook.ActiveSheet.Cells(RowCntr, 5).Text
                       Install_Time = ThisWorkbook.ActiveSheet.Cells(RowCntr, 6).Text
                       Removal_Time = ThisWorkbook.ActiveSheet.Cells(RowCntr, 7).Text
                       SA_Status = ThisWorkbook.ActiveSheet.Cells(RowCntr, 8).Text
                       SA_Start_Date = ThisWorkbook.ActiveSheet.Cells(RowCntr, 9).Text
                       SA_Start_Meter_Read = ThisWorkbook.ActiveSheet.Cells(RowCntr, 10).Text
                       Dispatch_Group = ThisWorkbook.ActiveSheet.Cells(RowCntr, 11).Text
                       Status = ThisWorkbook.ActiveSheet.Cells(RowCntr, 12).Text



            'User Initiated Stop Point
            If QUITTER = True Then
                MsgBox ("Process Halted by User")
                GoTo IThinkWereDoneHere
            End If

            'Error Handler
            If FieldOrderID = "" Then
                TryCount = TryCount + 1
                RowCntr = RowCntr + 1
                    If TryCount = 3 Then
                        MsgBox ("Encountered records missing Field Order ID. Process Complete.")
                        GoTo IThinkWereDoneHere
                    End If
                GoTo AssignCurrentVars
            End If

            'Skip records that have already been processed, even partially.
            If Status <> "" Then
                RowCntr = RowCntr + 1
                GoTo AssignCurrentVars
            End If

'Step 01a: Go to "Account Information" tab
iret = iim1.iimPlay("IH-CCB-AcctInfo")

'Step 02a: Click the Premise context menu and select "Go To Field Order"
iret = iim1.iimPlay("IH-ElecOpsCSD-GoTo_Premise_FO")

'Step 03a: Enter FOID, provided by the spreadsheet, into "Field Order ID" field and click related binoculars/search button.
iret = iim1.iimSet("FieldOrderID", FieldOrderID)
iret = iim1.iimPlay("IH-ElecOPSCSD-Input_FOID")

'Step 04a: Extract Field Order Status
iret = iim1.iimPlay("IH-ElecOpsCSD-Extract_FO_Status")
If iret = -1 Then
Status = "Stated Field Order ID doesn't exist in CC&B."
ThisWorkbook.ActiveSheet.Cells(RowCntr, 12).Value = Status

                iret = iim1.iimSet("UNAME", UN)
                iret = iim1.iimSet("PWORD", PW)
                iret = iim1.iimPlay("VH-ccb-logIn-User")

Else:
FO_Status = iim1.iimGetLastExtract(1)
ThisWorkbook.ActiveSheet.Cells(RowCntr, 2).Value = FO_Status
Status = "FO_Status has been extracted"
ThisWorkbook.ActiveSheet.Cells(RowCntr, 12).Value = Status
End If

'Step 04b: Extract Comments
iret = iim1.iimPlay("IH-ElecOpsCSD-Extract_FO_Comments")
FO_Comments = iim1.iimGetLastExtract(1)
ThisWorkbook.ActiveSheet.Cells(RowCntr, 3).Value = FO_Comments
Status = "FO_Comments have been extracted"
ThisWorkbook.ActiveSheet.Cells(RowCntr, 12).Value = Status

'Step 04c: Extract Dispatch Group
iret = iim1.iimPlay("IH-ElecOpsCSD-Extract_Dispatch_Grp")
Dispatch_Group = iim1.iimGetLastExtract(1)
ThisWorkbook.ActiveSheet.Cells(RowCntr, 11).Value = Dispatch_Group
Status = "Dispatch_Group has been extracted"
ThisWorkbook.ActiveSheet.Cells(RowCntr, 12).Value = Status

'Step 05a: Go to 'Activities' tab
iret = iim1.iimPlay("IH-CCB-GoTo_FOMain_FOActivities")

'Step 06a: Go to 'Service Point ID' context menu, and select "Go To Service Point"
iret = iim1.iimPlay("IH-ElecOpsCSD-GoTo_SPIDContext_SP")

'Step 07a: Go to 'Device History' tab
iret = iim1.iimPlay("IH-ElecOpsCSD-GoTo_DeviceHistory")

'Step 08a: Extract Badge Number
iret = iim1.iimPlay("IH-ElecOpsCSD-Extract_Badge")
Badge_Number = iim1.iimGetLastExtract(1)
ThisWorkbook.ActiveSheet.Cells(RowCntr, 4).Value = Badge_Number
Status = "Badge_Number has been extracted"
ThisWorkbook.ActiveSheet.Cells(RowCntr, 12).Value = Status

'Step 08b: Extract Device Type
iret = iim1.iimPlay("IH-ElecOpsCSD-Extract_Device_Type")
Device_Type = iim1.iimGetLastExtract(1)
ThisWorkbook.ActiveSheet.Cells(RowCntr, 5).Value = Device_Type
Status = "Device_Type has been extracted"
ThisWorkbook.ActiveSheet.Cells(RowCntr, 12).Value = Status

If Badge_Number = "#EANF#" Or Device_Type = "#EANF#" Then
Status = "No device history exists"
ThisWorkbook.ActiveSheet.Cells(RowCntr, 12).Value = Status
GoTo Step09a
Else:
GoTo Step08c
End If

'Step 08c: Extract Install Date/Time
Step08c:
iret = iim1.iimPlay("IH-ElecOpsCSD-Extract_InstallTime")
Install_Time_PreTrim = iim1.iimGetLastExtract(1)
Install_Time = Left(Install_Time_PreTrim, 10)
'Install_Time = Replace(Install_Time, "-", "/")
ThisWorkbook.ActiveSheet.Cells(RowCntr, 6).Value = Install_Time
Status = "Meter Install_Date/Time has been extracted"
ThisWorkbook.ActiveSheet.Cells(RowCntr, 12).Value = Status

'Step 08d: Extract Removal Date/Time
'iret = iim1.iimPlay("IH-ElecOpsCSD-Extract_RemovalTime")
'Removal_Time = iim1.iimGetLastExtract(1)
'ThisWorkbook.Sheets("Input&Output").Cells(RowCntr, 7).Value = Removal_Time
'Status = "Meter Removal_Date/Time has been extracted"
'ThisWorkbook.Sheets("Input&Output").Cells(RowCntr, 12).Value = Status

'Step 09a: Go to 'SP/SA' tab.
Step09a:
iret = iim1.iimPlay("IH-ElecOpsCSD-GoTo_SPSA")

'Step 09c: Go To 'Start Meter Read' context menu
If Badge_Number = "#EANF#" Or Device_Type = "#EANF#" Then
GoTo Step09b2
Else:
GoTo Step09c
Step09c:
iret = iim1.iimPlay("IH-ElecOpsCSD-GoTo_StartMeterRead")
End If

'Step 09d: Extract Register Reading.
iret = iim1.iimPlay("IH-ElecOpsCSD-Extract_MeterRead")
SA_Start_Meter_Read = iim1.iimGetLastExtract(1)
ThisWorkbook.ActiveSheet.Cells(RowCntr, 10).Value = SA_Start_Meter_Read
Status = "SA_Start_Meter_Read has been extracted"
ThisWorkbook.ActiveSheet.Cells(RowCntr, 12).Value = Status

If Badge_Number = "#EANF#" Or Device_Type = "#EANF#" Or Removal_Time = "#EANF#" Or SA_Start_Meter_Read = "#EANF#" Then
Status = "No device history exists"
ThisWorkbook.ActiveSheet.Cells(RowCntr, 12).Value = Status
'iret = iim1.iimPlay("VH-CCB-reset")
'RowCntr = RowCntr + 1
'GoTo AssignCurrentVars
End If

GoTo Step09b
'Step 09b: Go to 'Service Agreement' context menu and select "Go To Service Agreement"
'iret = iim1.iimPlay("IH-ElecOpsCSD-GoTo_SPSA_SA_SA")
Step09b2:
iret = iim1.iimPlay("IH-ElecOpsCSD-GoTo_SA")
GoTo Step10
Step09b:
iret = iim1.iimPlay("IH-ElecOpsCSD-GoTo_Back_SA")

'Step 10a: Extract SA Status
Step10:
iret = iim1.iimPlay("IH-ElecOpsCSD-Extract_SAStatus")
SA_Status = iim1.iimGetLastExtract(1)
ThisWorkbook.ActiveSheet.Cells(RowCntr, 8).Value = SA_Status
Status = "SA_Status has been extracted"
ThisWorkbook.ActiveSheet.Cells(RowCntr, 12).Value = Status

'Step 10b: Extract SA Date
iret = iim1.iimPlay("IH-ElecOpsCSD-Extract_SADate")
SA_Start_Date = iim1.iimGetLastExtract(1)
ThisWorkbook.ActiveSheet.Cells(RowCntr, 9).Value = SA_Start_Date
Status = "SA Start_Date has been extracted"
ThisWorkbook.ActiveSheet.Cells(RowCntr, 12).Value = Status
If Install_Time <> "" And SA_Start_Date <> Install_Time Then
Status = "SA Start Date and Meter Install Dates do not match."
ThisWorkbook.ActiveSheet.Cells(RowCntr, 12).Value = Status
GoTo Step11
Else:
Status = "Completed. Necessary information extracted."
ThisWorkbook.ActiveSheet.Cells(RowCntr, 12).Value = Status
End If
GoTo Step11

'Step 11: Replace #EANF# with null values for better readability
Step11:
If Badge_Number = "#EANF#" Then
Badge_Number = Replace(Badge_Number, "#EANF#", "")
ThisWorkbook.ActiveSheet.Cells(RowCntr, 4).Value = Badge_Number
Else:
End If
If Device_Type = "#EANF#" Then
Device_Type = Replace(Device_Type, "#EANF#", "")
ThisWorkbook.ActiveSheet.Cells(RowCntr, 5).Value = Device_Type
Status = "No Meter set."
ThisWorkbook.ActiveSheet.Cells(RowCntr, 12).Value = Status
Else:
End If
If SA_Start_Date = "#EANF#" Then
SA_Start_Date = Replace(SA_Start_Date, "#EANF#", "")
ThisWorkbook.ActiveSheet.Cells(RowCntr, 9).Value = SA_Start_Date
Else:
End If
If SA_Status = "#EANF#" Then
SA_Status = Replace(SA_Status, "#EANF#", "")
ThisWorkbook.ActiveSheet.Cells(RowCntr, 8).Value = SA_Status
Else:
End If
If SA_Start_Meter_Read = "#EANF#" Then
SA_Start_Meter_Read = Replace(SA_Start_Meter_Read, "#EANF#", "")
ThisWorkbook.ActiveSheet.Cells(RowCntr, 10).Value = SA_Start_Meter_Read
Else:
End If

'Step 12a: Reset CC&B.
iret = iim1.iimPlay("VH-CCB-reset")

Loop Until QUITTER = True Or RowCntr = 10000

ElseIf ThisWorkbook.ActiveSheet.Cells(RowCntr, 1).Value <> "" Then
RowCntr = 2
GoTo AssignCurrentVars
ElseIf ThisWorkbook.ActiveSheet.Cells(RowCntr, 12).Value <> "" Then
End If
End If
Workbooks("ElecOpsCSD_FollowUp_iMacro.xlsm").Activate
'RowCntr = 2
Next ws '**THIS IS WHERE I AM GETTING THE COMPILE ERROR**

Loop Until ws.Name = "CC&B_Process"


IThinkWereDoneHere:
ThisWorkbook.Sheets("Control").Cells(4, 2) = Now()
ThisWorkbook.Save
iret = iim1.iimExit()
End Sub

1 个答案:

答案 0 :(得分:0)

我找不到丢失的循环或下一个迭代器,但是您发布的代码缺少If行:

If ws.Name <> "Control" And _
   ws.Name <> "OutputArchive" And ws.Name <> "CC&B_Process" Then

似乎没有任何结尾End If

看起来应该放在Next ws行之前(我的猜测):

    End If
  Next ws
Loop Until ws.Name = "CC&B_Process"

你对GoTo的自由使用被认为是不好的做法。

相关问题