I want to start off by apologizing for my basic understanding of VBA and the coding language. I have gone through numerous threads to try and piece together a macro to suit my needs but continue to run into issues due to my limited understanding. Any help is appreciated since it currently takes me a few days to collect this data by hand whereas a macro could probably pull it all in minutes.
The macro I am needing would essentially allow me to plug values from Excel into Attachmate and then pull data from several pages in Attachmate back over to Excel.
Here is what I have so far (with errors and what I cannot figure out of course ):
The macro I am needing would essentially allow me to plug values from Excel into Attachmate and then pull data from several pages in Attachmate back over to Excel.
Here is what I have so far (with errors and what I cannot figure out of course ):
Code:
Sub DataExtraction()
Dim Sessions, System As Object, Sess0 As Object
Set System = CreateObject("EXTRA.System")
Set Sessions = System.Sessions
Set Sess0 = System.ActiveSession
'----------------------------------
'Data begins in row 2 column A
'where each value in A is 6 alphanumerical bytes
'columns B through L would be pulled from Attachmate
'I would like these to go into a different sheet in Excel
'----------------------------------
rw = 2
rw1 = 1
With Worksheets("Workbook")
For x = rw To ActiveSheet.Rows.Count
PO = .Cells(x, 1)
PA = .Cells(x, 6)
'-----First Part of Attachmate Coding to be Retrieved-------
If PO = "" Then Exit Sub
Sess0.Screen.MoveTo 3, 8
Sess0.Screen.PutString PO, 2, 6
Sess0.Screen.MoveTo 5, 22
Sess0.Screen.SendKeys ("CG")
Sess0.Screen.SendKeys ("<Enter>")
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
GroupName = Sess0.Screen.GetString(6, 17, 40)
.Cells(rw1, 2) = GroupName
Do
For r = 11 To 22
dd = 11
SubGroup = Sess0.Screen.GetString(r, 7, 10)
If SubGroup = "**********" Then
Exit Do
Else
EDate = Sess0.Screen.GetString(r, 51, 8)
Fund = Sess0.Screen.GetString(r, 44, 1)
Plan = Sess0.Screen.GetString(r, 18, 18)
PLine = Sess0.Screen.GetString(r, 38, 4)
rw1 = rw1 + 1
.Cells(rw1, 3) = EDate
.Cells(rw1, 4) = Fund
.Cells(rw1, 5) = Plan
.Cells(rw1, 6) = SubGroup
.Cells(rw1, 13) = PLine
End If
Next r
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.SendKeys ("<Pf8>")
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
'----------------------------------
'If there are values in r 22
'I need the data pulled and then a command
'given to go to the next page "<Pf8>" and
'loop until no more values/subgroups
'----------------------------------
Loop
'-----Second Part of Attachmate Coding to be Retrieved-------
Do
If PA = "" Then Exit Do
Sess0.Screen.MoveTo 3, 31
Sess0.Screen.PutString PA, 2, 10
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.PutString "CA", 5, 22
Sess0.Screen.SendKeys ("<Enter>")
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
CCode = Sess0.Screen.GetString(6, 21, 4)
rw1 = rw1 + 1
.Cells(rw1, 7) = CCode
Loop
'-----Third Part of Attachmate Coding to be Retrieved-------
If PA = "" Then Exit Sub
Sess0.Screen.MoveTo 3, 31
Sess0.Screen.PutString PA, 2, 10
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.PutString "VV", 5, 22
Sess0.Screen.SendKeys ("<Enter>")
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Do
For r = 8 To 18
dd = 8
Selection = Sess0.Screen.GetString(r, 8, 3)
If Selection = "EMD" Then
Sess0.Screen.PutString "S", r, 4
Sess0.Screen.SendKeys ("<Enter>")
'----------------------------------
'I need it to look specifically for
'the presence of "EMD" and then send a
'command "S" next to it followed by "<Enter>"
'to access the page with data I need to pull
'----------------------------------
BLEDate = Sess0.Screen.GetString(11, 49, 8)
PC = Sess0.Screen.GetString(11, 20, 7)
BL1 = Sess0.Screen.GetString(15, 3, 4)
BL2 = Sess0.Screen.GetString(15, 18, 4)
BL3 = Sess0.Screen.GetString(15, 38, 4)
rw1 = rw1 + 1
.Cells(rw1, 3) = PC
.Cells(rw1, 4) = BL1
.Cells(rw1, 5) = BL2
.Cells(rw1, 6) = BL3
.Cells(rw1, 13) = BLEDate
Else
End If
Next r
Exit Do
Loop
Next x 'next row/group
End With
End Sub