Code:
Sub MUFS_Scrubbing()
Dim Sessions As Object
Dim System As Object
Set System = GetObject("", "Extra.system") ' Gets the system object
If (System Is Nothing) Then
MsgBox "Could not create the EXTRA System object. Stopping macro playback."
Stop
End If
Set Sessions = System.Sessions
If (Sessions Is Nothing) Then
MsgBox "Could not create the EXTRA System object. Stopping macro playback."
Stop
End If
' Set the default wait timeout value
g_HostSettleTime = 1 ' milliseconds
OldSystemTimeout& = System.Timeoutvalue
If (g_HostSettleTime > OldSystemTimeout) Then
System.Timeoutvalue = g_HostSettleTime
End If
'--------------------------------------------------------------------
'Get the necessary Session Object
Dim Sess0 As Object
Set Sess0 = System.ActiveSession
If (Sess0 Is Nothing) Then
MsgBox "Could not create the Session object. Stopping macro playback."
Stop
End If
If Not Sess0.Visible Then Sess0.Visible = True
Sess0.screen.WaitHostQuiet (g_HostSettleTime)
'Start the Loop
Dim Row As Long
With Worksheets("MUFS Scrub")
End With
LastRow = ActiveSheet.UsedRange.Rows.Count
For Row = 2 To LastRow
Do
Sess0.screen.SendKeys ("<PF11>")
Sess0.screen.WaitHostQuiet (g_HostSettleTime)
Sess0.screen.SendKeys ("21")
Sess0.screen.WaitHostQuiet (g_HostSettleTime)
Sess0.screen.MoveTo 6, 19
Sess0.screen.PutString Trim(Cells(Row, 1)), 6, 19
Sess0.screen.SendKeys ("<tab>")
Sess0.screen.MoveTo 6, 25
Sess0.screen.PutString Trim(Cells(Row, 2)), , 6, 25
Sess0.screen.SendKeys ("<tab>")
Sess0.screen.MoveTo 6, 36
Sess0.screen.PutString Trim(Cells(Row, 3)), , 6, 36
Sess0.screen.SendKeys ("<Enter>")
Sess0.screen.WaitHostQuiet (g_HostSettleTime)
Primary_Zip = Sess0.screen.getstring(14, 66, 5)
Cells(Row, 11).Value = Primary_Zip
Row = Row + 1
Next Row
Loop
End Sub
I am relatively new to writing macros in Excel. I am not sure why I am receiving the compile error "Next without For". Eventually, there will be more steps in the looped process, not just pulling a zip code. However, I wanted to get the look-up code all set first. The code works except for the loop. Without the "Next Row", it looks up the first record, pulls back the zip code and continuously loops through the first record (obviously because it's not going to the next row on the sheet).
Any assistance will be appreciated.