Hello Again!
After a few years since my last post I've been able to adapt the original macro that was created with great help from the community and make it perform numerous functions. Now, I'm looking to essentially have an extension of that original macro in excel screen scrape some different data from the Attachmate session but have run into a roadblock with the logistics.
The below code (still a work in progress and apologies as the code feature was presenting an error) has 'PO' as the input from excel into Attachmate to begin the process. The Attachmate session will then return records based off the 'PO' value into rows 8-21 on the screen. The macro will go record by record and look for location 'S' to be null while location 'I' has a value, it will then use input the selection code 'I' value to move into another screen for that specific record. This secondary screen will have more detailed information which will be screen scraped into excel before sending the PF3 function key to return to the list of records. Once the macro reaches the last record in row 21, it will then use the PF8 function key to move onto the next page of records and will loop the process. The issue I am running into is that for records on the second screen the macro will use the 'I' value to go into a record's secondary screen and scrape the data correctly but the PF3 function key returns to the original/first page of records and would start looping through that page again rather than moving back to the second page and continuing on with the next record. There are no identifiers between the pages (i.e. a location in the session that says page 1 of 2 or something similar) which I could have the macro look for unfortunately so I'm thinking there needs to be syntax built into the macro to use the PF8 function key the necessary amount of times to return to the screen it left off on but I'm not familiar with what the best method would be or really how to do that. Any ideas are appreciated!
Sub RecordLookUp()
Dim Sessions, System As Object, Sess0 As Object, PO As String, WB As Workbook, WS As Worksheet
Set System = CreateObject("EXTRA.System")
Set Sessions = System.Sessions
Set Sess0 = System.ActiveSession
Set WB = ActiveWorkbook
Set WS = Sheets("Look-up")
rw = 2
rw1 = 1
With Worksheets("Look-up")
Do
For X = rw To ActiveSheet.Rows.Count
PO = Left(Sheets("Look-up").Cells(X, 1).Value, 9)
If PO = "000000000" Then Exit Sub
Sess0.Screen.MoveTo 5, 22
Sess0.Screen.SendKeys ("BA")
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Sess0.Screen.MoveTo 5, 22
Sess0.Screen.SendKeys ("BA")
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Sess0.Screen.MoveTo 5, 22
Sess0.Screen.SendKeys ("CD")
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
'Input value from Excel to Attachmate
Sess0.Screen.MoveTo 3, 44
Sess0.Screen.SendKeys PO
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Do
For r = 8 To 21
dd = 1
S = Trim(Sess0.Screen.GetString(r, 33, 8))
I = Trim(Sess0.Screen.GetString(r, 2, 2))
ML = Trim(Sess0.Screen.GetString(2, 23, 7))
'If both S and I are null -> end
If S = "" And I = "" Then
Exit Do
'If S is null but I is not, move into secondary screen with more detailed information
ElseIf S = "" Then
Sess0.Screen.MoveTo 5, 18
Sess0.Screen.SendKeys I
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
If ML = "INQUIRY" Then
CONT = Sess0.Screen.GetString(4, 28, 4)
ID = Sess0.Screen.GetString(3, 44, 9)
ENTITY = Sess0.Screen.GetString(4, 9, 6)
PRDGRP = Sess0.Screen.GetString(4, 28, 6)
Date1 = Sess0.Screen.GetString(18, 64, 8)
Date2 = Sess0.Screen.GetString(18, 73, 8)
MCode = Sess0.Screen.GetString(4, 62, 2)
ISB = Sess0.Screen.GetString(9, 10, 8)
FR = Trim(Sess0.Screen.GetString(5, 51, 13))
MA = Sess0.Screen.GetString(5, 69, 1)
LA = Trim(Sess0.Screen.GetString(5, 12, 27))
SN = Sess0.Screen.GetString(8, 23, 9)
SR = Trim(Sess0.Screen.GetString(6, 14, 25))
CT = Trim(Sess0.Screen.GetString(6, 45, 25))
ST = Sess0.Screen.GetString(6, 78, 2)
ZP = Sess0.Screen.GetString(7, 6, 5)
rw1 = rw1 + 1
Sheets("Workbook").Cells(rw1, 1) = CONT
Sheets("Workbook").Cells(rw1, 2) = ID
Sheets("Workbook").Cells(rw1, 3) = ENTITY
Sheets("Workbook").Cells(rw1, 4) = PRDGRP
Sheets("Workbook").Cells(rw1, 5) = Date1
Sheets("Workbook").Cells(rw1, 6) = Date2
Sheets("Workbook").Cells(rw1, 7) = MCode
Sheets("Workbook").Cells(rw1, 8) = ISB
Sheets("Workbook").Cells(rw1, 9) = FR
Sheets("Workbook").Cells(rw1, 10) = MA
Sheets("Workbook").Cells(rw1, 11) = LA
Sheets("Workbook").Cells(rw1, 12) = SN
Sheets("Workbook").Cells(rw1, 13) = SR
Sheets("Workbook").Cells(rw1, 14) = CT
Sheets("Workbook").Cells(rw1, 15) = ST
Sheets("Workbook").Cells(rw1, 16) = ZP
Else
CONT = Sess0.Screen.GetString(4, 28, 4)
ID = Sess0.Screen.GetString(3, 44, 9)
ENTITY = Sess0.Screen.GetString(4, 9, 6)
PRDGRP = Sess0.Screen.GetString(4, 28, 6)
Date1 = Sess0.Screen.GetString(20, 21, 8)
Date2 = Sess0.Screen.GetString(20, 31, 8)
MCode = Sess0.Screen.GetString(4, 62, 2)
ISB = Sess0.Screen.GetString(9, 10, 8)
FR = Trim(Sess0.Screen.GetString(5, 51, 13))
MA = Sess0.Screen.GetString(5, 69, 1)
LA = Trim(Sess0.Screen.GetString(5, 12, 27))
SN = Sess0.Screen.GetString(9, 72, 9)
SR = Trim(Sess0.Screen.GetString(6, 14, 25))
CT = Trim(Sess0.Screen.GetString(6, 45, 25))
ST = Sess0.Screen.GetString(6, 77, 2)
ZP = Sess0.Screen.GetString(7, 6, 5)
rw1 = rw1 + 1
Sheets("Workbook").Cells(rw1, 1) = CONT
Sheets("Workbook").Cells(rw1, 2) = ID
Sheets("Workbook").Cells(rw1, 3) = ENTITY
Sheets("Workbook").Cells(rw1, 4) = PRDGRP
Sheets("Workbook").Cells(rw1, 5) = Date1
Sheets("Workbook").Cells(rw1, 6) = Date2
Sheets("Workbook").Cells(rw1, 7) = MCode
Sheets("Workbook").Cells(rw1, 8) = ISB
Sheets("Workbook").Cells(rw1, 9) = FR
Sheets("Workbook").Cells(rw1, 10) = MA
Sheets("Workbook").Cells(rw1, 11) = LA
Sheets("Workbook").Cells(rw1, 12) = SN
Sheets("Workbook").Cells(rw1, 13) = SR
Sheets("Workbook").Cells(rw1, 14) = CT
Sheets("Workbook").Cells(rw1, 15) = ST
Sheets("Workbook").Cells(rw1, 16) = ZP
End If
'Return to records screen
Sess0.Screen.SendKeys ("<Pf3>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
'Exit Do
End If
Next r
'Next page
Sess0.Screen.SendKeys ("<Pf8>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Loop
Sess0.Screen.SendKeys ("<Pf3>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Sess0.Screen.SendKeys ("<Pf3>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Sess0.Screen.SendKeys ("<Pf3>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Next X 'next row/group
Loop
End With
End Sub
After a few years since my last post I've been able to adapt the original macro that was created with great help from the community and make it perform numerous functions. Now, I'm looking to essentially have an extension of that original macro in excel screen scrape some different data from the Attachmate session but have run into a roadblock with the logistics.
The below code (still a work in progress and apologies as the code feature was presenting an error) has 'PO' as the input from excel into Attachmate to begin the process. The Attachmate session will then return records based off the 'PO' value into rows 8-21 on the screen. The macro will go record by record and look for location 'S' to be null while location 'I' has a value, it will then use input the selection code 'I' value to move into another screen for that specific record. This secondary screen will have more detailed information which will be screen scraped into excel before sending the PF3 function key to return to the list of records. Once the macro reaches the last record in row 21, it will then use the PF8 function key to move onto the next page of records and will loop the process. The issue I am running into is that for records on the second screen the macro will use the 'I' value to go into a record's secondary screen and scrape the data correctly but the PF3 function key returns to the original/first page of records and would start looping through that page again rather than moving back to the second page and continuing on with the next record. There are no identifiers between the pages (i.e. a location in the session that says page 1 of 2 or something similar) which I could have the macro look for unfortunately so I'm thinking there needs to be syntax built into the macro to use the PF8 function key the necessary amount of times to return to the screen it left off on but I'm not familiar with what the best method would be or really how to do that. Any ideas are appreciated!
Sub RecordLookUp()
Dim Sessions, System As Object, Sess0 As Object, PO As String, WB As Workbook, WS As Worksheet
Set System = CreateObject("EXTRA.System")
Set Sessions = System.Sessions
Set Sess0 = System.ActiveSession
Set WB = ActiveWorkbook
Set WS = Sheets("Look-up")
rw = 2
rw1 = 1
With Worksheets("Look-up")
Do
For X = rw To ActiveSheet.Rows.Count
PO = Left(Sheets("Look-up").Cells(X, 1).Value, 9)
If PO = "000000000" Then Exit Sub
Sess0.Screen.MoveTo 5, 22
Sess0.Screen.SendKeys ("BA")
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Sess0.Screen.MoveTo 5, 22
Sess0.Screen.SendKeys ("BA")
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Sess0.Screen.MoveTo 5, 22
Sess0.Screen.SendKeys ("CD")
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
'Input value from Excel to Attachmate
Sess0.Screen.MoveTo 3, 44
Sess0.Screen.SendKeys PO
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Do
For r = 8 To 21
dd = 1
S = Trim(Sess0.Screen.GetString(r, 33, 8))
I = Trim(Sess0.Screen.GetString(r, 2, 2))
ML = Trim(Sess0.Screen.GetString(2, 23, 7))
'If both S and I are null -> end
If S = "" And I = "" Then
Exit Do
'If S is null but I is not, move into secondary screen with more detailed information
ElseIf S = "" Then
Sess0.Screen.MoveTo 5, 18
Sess0.Screen.SendKeys I
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
If ML = "INQUIRY" Then
CONT = Sess0.Screen.GetString(4, 28, 4)
ID = Sess0.Screen.GetString(3, 44, 9)
ENTITY = Sess0.Screen.GetString(4, 9, 6)
PRDGRP = Sess0.Screen.GetString(4, 28, 6)
Date1 = Sess0.Screen.GetString(18, 64, 8)
Date2 = Sess0.Screen.GetString(18, 73, 8)
MCode = Sess0.Screen.GetString(4, 62, 2)
ISB = Sess0.Screen.GetString(9, 10, 8)
FR = Trim(Sess0.Screen.GetString(5, 51, 13))
MA = Sess0.Screen.GetString(5, 69, 1)
LA = Trim(Sess0.Screen.GetString(5, 12, 27))
SN = Sess0.Screen.GetString(8, 23, 9)
SR = Trim(Sess0.Screen.GetString(6, 14, 25))
CT = Trim(Sess0.Screen.GetString(6, 45, 25))
ST = Sess0.Screen.GetString(6, 78, 2)
ZP = Sess0.Screen.GetString(7, 6, 5)
rw1 = rw1 + 1
Sheets("Workbook").Cells(rw1, 1) = CONT
Sheets("Workbook").Cells(rw1, 2) = ID
Sheets("Workbook").Cells(rw1, 3) = ENTITY
Sheets("Workbook").Cells(rw1, 4) = PRDGRP
Sheets("Workbook").Cells(rw1, 5) = Date1
Sheets("Workbook").Cells(rw1, 6) = Date2
Sheets("Workbook").Cells(rw1, 7) = MCode
Sheets("Workbook").Cells(rw1, 8) = ISB
Sheets("Workbook").Cells(rw1, 9) = FR
Sheets("Workbook").Cells(rw1, 10) = MA
Sheets("Workbook").Cells(rw1, 11) = LA
Sheets("Workbook").Cells(rw1, 12) = SN
Sheets("Workbook").Cells(rw1, 13) = SR
Sheets("Workbook").Cells(rw1, 14) = CT
Sheets("Workbook").Cells(rw1, 15) = ST
Sheets("Workbook").Cells(rw1, 16) = ZP
Else
CONT = Sess0.Screen.GetString(4, 28, 4)
ID = Sess0.Screen.GetString(3, 44, 9)
ENTITY = Sess0.Screen.GetString(4, 9, 6)
PRDGRP = Sess0.Screen.GetString(4, 28, 6)
Date1 = Sess0.Screen.GetString(20, 21, 8)
Date2 = Sess0.Screen.GetString(20, 31, 8)
MCode = Sess0.Screen.GetString(4, 62, 2)
ISB = Sess0.Screen.GetString(9, 10, 8)
FR = Trim(Sess0.Screen.GetString(5, 51, 13))
MA = Sess0.Screen.GetString(5, 69, 1)
LA = Trim(Sess0.Screen.GetString(5, 12, 27))
SN = Sess0.Screen.GetString(9, 72, 9)
SR = Trim(Sess0.Screen.GetString(6, 14, 25))
CT = Trim(Sess0.Screen.GetString(6, 45, 25))
ST = Sess0.Screen.GetString(6, 77, 2)
ZP = Sess0.Screen.GetString(7, 6, 5)
rw1 = rw1 + 1
Sheets("Workbook").Cells(rw1, 1) = CONT
Sheets("Workbook").Cells(rw1, 2) = ID
Sheets("Workbook").Cells(rw1, 3) = ENTITY
Sheets("Workbook").Cells(rw1, 4) = PRDGRP
Sheets("Workbook").Cells(rw1, 5) = Date1
Sheets("Workbook").Cells(rw1, 6) = Date2
Sheets("Workbook").Cells(rw1, 7) = MCode
Sheets("Workbook").Cells(rw1, 8) = ISB
Sheets("Workbook").Cells(rw1, 9) = FR
Sheets("Workbook").Cells(rw1, 10) = MA
Sheets("Workbook").Cells(rw1, 11) = LA
Sheets("Workbook").Cells(rw1, 12) = SN
Sheets("Workbook").Cells(rw1, 13) = SR
Sheets("Workbook").Cells(rw1, 14) = CT
Sheets("Workbook").Cells(rw1, 15) = ST
Sheets("Workbook").Cells(rw1, 16) = ZP
End If
'Return to records screen
Sess0.Screen.SendKeys ("<Pf3>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
'Exit Do
End If
Next r
'Next page
Sess0.Screen.SendKeys ("<Pf8>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Loop
Sess0.Screen.SendKeys ("<Pf3>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Sess0.Screen.SendKeys ("<Pf3>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Sess0.Screen.SendKeys ("<Pf3>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Next X 'next row/group
Loop
End With
End Sub