Hi,
I'm new to VBA and it's really hard to any information online. I have written a code to basically scrape values from the DD.3 screen and paste them into excel sheet.
The code executes without any issues in debug mode, but the cursor seems to have a mind of its own when I run the code.
Any help would be much appreciated.
Sub Main()
Dim Sys As Object, Sess As Object, MyScreen As Object, MyArea As Object
Dim oWS As Worksheet
Set Sys = CreateObject("EXTRA.System")
Dim SIN As String
' Assumes an open session
Set Sess = Sys.ActiveSession
Set MyScreen = Sess.Screen
Set oWS = ThisWorkbook.Sheets("DATA") '... Stores reference to data worksheet
Row = 2
lastRow = oWS.Cells(50000, 1).End(xlUp).Row
For Row = 2 To lastRow
SIN = Trim(oWS.Cells(Row, 1))
MyScreen.MoveTo 1, 20
MyScreen.SendKeys (SIN)
MyScreen.SendKeys ("<enter>")
Do Until Len(MyScreen.Search("T4 ")) > 0 Or MyScreen.GetString(2, 2, 6) = "ME 039"
MyScreen.MoveTo 1, 1
MyScreen.SendKeys ("<pf8>")
Loop
If Len(MyScreen.Search("T4 ")) > 0 Then
MyScreen.MoveTo MyScreen.Search("T4 ").Bottom, MyScreen.Search("T4 ").Right - 12
MyScreen.SendKeys ("x")
MyScreen.SendKeys ("<enter>")
Do Until MyScreen.GetString(1, 67, 3) <> "T4 " Or MyScreen.GetString(2, 2, 6) = "ME 039"
For i = 2 To 15
If MyScreen.GetString(1, 67, 3) = "T4 " Then
oWS.Cells(Row, i) = MyScreen.GetString(21, 16, 10)
MyScreen.SendKeys ("<pf8>")
If MyScreen.GetString(2, 2, 6) = "ME 039" Then
i = 15
End If
End If
Next i
Loop
If MyScreen.GetString(2, 2, 6) = "ME 039" Then
End If
End If
Next
End Sub
I'm new to VBA and it's really hard to any information online. I have written a code to basically scrape values from the DD.3 screen and paste them into excel sheet.
The code executes without any issues in debug mode, but the cursor seems to have a mind of its own when I run the code.
Any help would be much appreciated.
Sub Main()
Dim Sys As Object, Sess As Object, MyScreen As Object, MyArea As Object
Dim oWS As Worksheet
Set Sys = CreateObject("EXTRA.System")
Dim SIN As String
' Assumes an open session
Set Sess = Sys.ActiveSession
Set MyScreen = Sess.Screen
Set oWS = ThisWorkbook.Sheets("DATA") '... Stores reference to data worksheet
Row = 2
lastRow = oWS.Cells(50000, 1).End(xlUp).Row
For Row = 2 To lastRow
SIN = Trim(oWS.Cells(Row, 1))
MyScreen.MoveTo 1, 20
MyScreen.SendKeys (SIN)
MyScreen.SendKeys ("<enter>")
Do Until Len(MyScreen.Search("T4 ")) > 0 Or MyScreen.GetString(2, 2, 6) = "ME 039"
MyScreen.MoveTo 1, 1
MyScreen.SendKeys ("<pf8>")
Loop
If Len(MyScreen.Search("T4 ")) > 0 Then
MyScreen.MoveTo MyScreen.Search("T4 ").Bottom, MyScreen.Search("T4 ").Right - 12
MyScreen.SendKeys ("x")
MyScreen.SendKeys ("<enter>")
Do Until MyScreen.GetString(1, 67, 3) <> "T4 " Or MyScreen.GetString(2, 2, 6) = "ME 039"
For i = 2 To 15
If MyScreen.GetString(1, 67, 3) = "T4 " Then
oWS.Cells(Row, i) = MyScreen.GetString(21, 16, 10)
MyScreen.SendKeys ("<pf8>")
If MyScreen.GetString(2, 2, 6) = "ME 039" Then
i = 15
End If
End If
Next i
Loop
If MyScreen.GetString(2, 2, 6) = "ME 039" Then
End If
End If
Next
End Sub