I will admit that I do not know VBA so please bear with my ignorance. I work for a very small company and we do not have any experts in this area. Enough about that.
I have the following code that does a screen scrape from Reflections - Attachmate and its not working.
The error I get is Compile Error - Variable not defined......screen shot attached.
It highlights this line of code.
Set Sessions = System.Sessions
Here is all the code...
Public Sub StartProcess()
Dim oSheet As Worksheet
Dim bIsStartDate As Boolean
Dim sMonth As String
Dim sBeginningValue As String
Dim sReceiptDate As String
Dim sMonthPremiumIsPayingFor As String
Dim sContributions As String
Dim sPremiumTax As String
Dim sAdminFee As String
Dim sCostofInsurance As String
Dim sDisbursement As String
Dim sInterest As String
Dim lRowIndexMF As Long
Dim lRowIndexXL As Long
Dim sTransCode As String
Dim sCheck As String
Dim iTransaction_year As Integer
Dim sPrevMonth As String
Dim sPrevCostofInsurance As String
Set Sessions = System.Sessions
Set oSheet = ActiveSheet
lRowIndexMF = 13
lRowIndexXL = START_ROW
If bIsStartDate = True Then
Else
oSheet.Range("k6").Value = "0"
End If
Do
sCheck = Trim(Session.GetText(lRowIndexMF, 0, lRowIndexMF, 80))
Select Case sCheck
Case "": GoTo NxtLine
Case Else:
If (InStr(sCheck, "COST") > 0) Or (Not (IsNumeric(VBA.Left(sCheck, 4)))) Then
GoTo NxtLine
End If
End Select
lRowIndexXL = lRowIndexXL + 1
'Read Values
sMonth = Session.GetText(lRowIndexMF, 76, lRowIndexMF, 80)
'sBeginningValue = Session.GetText(lRowIndexMF, 1, lRowIndexMF, 6)
sReceiptDate = Session.GetText(lRowIndexMF, 0, lRowIndexMF, 4)
sMonthPremiumIsPayingFor = Session.GetText(lRowIndexMF, 12, lRowIndexMF, 14)
'sMonthPremiumIsPayingFor = Session.GetText(lRowIndexMF, 6, lRowIndexMF, 10)
sContributions = Trim(Session.GetText(lRowIndexMF, 26, lRowIndexMF, 35))
'On Error Resume Next
If Trim(sContributions) <> "" Then
sContributions = IIf(Right(Trim(sContributions), 1) = "-", -Mid(Trim(sContributions), 1, Len(Trim(sContributions)) - 1), Trim(sContributions))
End If
'On Error GoTo 0
sPremiumTax = Trim(Session.GetText(lRowIndexMF, 36, lRowIndexMF, 43))
If Len(Trim(sPremiumTax)) > 0 Then
sPremiumTax = IIf(Right(Trim(sPremiumTax), 1) = "-", -Mid(Trim(sPremiumTax), 1, Len(Trim(sPremiumTax)) - 1), Trim(sPremiumTax))
End If
sAdminFee = Trim(Session.GetText(lRowIndexMF, 44, lRowIndexMF, 49))
sCostofInsurance = Trim(Session.GetText(lRowIndexMF, 50, lRowIndexMF, 58))
sDisbursement = 0 'Session.GetText(lRowIndexMF, 1, lRowIndexMF, 6)
sInterest = Trim(Session.GetText(lRowIndexMF, 59, lRowIndexMF, 67))
sTransCode = Session.GetText(lRowIndexMF, 16, lRowIndexMF, 17)
'Debug.Print Format(VBA.Right(sMonth, 2) & "/01/" & VBA.Left(sMonth, 2), "mmm")
'Update Excel
If sMonth = "0000" Then
If lRowIndexXL = START_ROW Then
oSheet.Range("A" & lRowIndexXL).Value = "ERROR"
'sMonth = "ERROR"
GoTo NxtEntry
Else
'oSheet.Range("A" & lRowIndexXL).Value = oSheet.Range("A" & lRowIndexXL - 1).Value
sMonth = Format(oSheet.Range("A" & lRowIndexXL - 1).Value, "yy") & Format(oSheet.Range("A" & lRowIndexXL - 1).Value, "mm")
End If
End If
oSheet.Range("A" & lRowIndexXL).Select
oSheet.Range("A" & lRowIndexXL).Value = "'" & Format(VBA.Right(sMonth, 2) & "/01/" & VBA.Left(sMonth, 2), "mmm") & "-" & Format(VBA.Right(sMonth, 2) & "/01/" & VBA.Left(sMonth, 2), "yy")
NxtEntry:
'oSheet.Range("B" & lRowIndexXL).Value = sBeginningValue
'oSheet.Range("C" & lRowIndexXL).Value = Format(VBA.Mid(sReceiptDate, 2, 2) & "/" & VBA.Right(sReceiptDate, 2) & "/" & VBA.Left(sMonth, 2), "mm/dd/yyyy")
'oSheet.Range("D" & lRowIndexXL).Value = "'" & Format(VBA.Right(sMonthPremiumIsPayingFor, 2) & "/01/" & VBA.Left(sMonth, 2), "mmm") & "-" & Format(VBA.Right(sMonthPremiumIsPayingFor, 2) & "/01/" & VBA.Left(sMonth, 2), "yy")
oSheet.Range("C" & lRowIndexXL).Value = Format(VBA.Mid(sReceiptDate, 2, 2) & "/" & VBA.Right(sReceiptDate, 2) & "/" & GetTransactionYear(sMonth, sReceiptDate), "mm/dd/yyyy")
oSheet.Range("D" & lRowIndexXL).Value = "'" & Format(VBA.Right(sMonthPremiumIsPayingFor, 2) & "/01/" & VBA.Left(sMonth, 2), "mmm") & "-" & Format(VBA.Right(sMonthPremiumIsPayingFor, 2) & "/01/" & GetTransactionYear(sMonth, sMonthPremiumIsPayingFor), "yy")
oSheet.Range("E" & lRowIndexXL).Value = sContributions
oSheet.Range("F" & lRowIndexXL).Value = IIf(sPremiumTax = "", 0, -Val(sPremiumTax))
oSheet.Range("G" & lRowIndexXL).Value = IIf(sAdminFee = "", sAdminFee, -Val(sAdminFee))
If InStr(sCostofInsurance, ".") > 0 Then
oSheet.Range("H" & lRowIndexXL).Value = -sCostofInsurance
Else
oSheet.Range("H" & lRowIndexXL).Value = oSheet.Range("H" & lRowIndexXL - 1).Value
End If
If sPrevMonth = sMonth Then
If InStr(sPrevCostofInsurance, ".") = 0 Then
oSheet.Range("H" & lRowIndexXL).Value = 0
End If
End If
Select Case sTransCode
Case "31", "32", "34", "37":
sDisbursement = sContributions
oSheet.Range("E" & lRowIndexXL).Value = "0"
Case "05"
oSheet.Range("E" & lRowIndexXL).Value = "0"
End Select
oSheet.Range("I" & lRowIndexXL).Value = sDisbursement
oSheet.Range("J" & lRowIndexXL).Value = sInterest
sPrevMonth = sMonth
sPrevCostofInsurance = sCostofInsurance
Call EnterFormulas(lRowIndexXL, oSheet)
NxtLine:
If lRowIndexMF = 24 Then
lRowIndexMF = 13
'next page
Session.TransmitTerminalKey (rcHpF4Key)
Application.Wait (Now + TimeValue("00:00:02"))
Else
lRowIndexMF = lRowIndexMF + 1
End If
Loop While VBA.Trim((Session.GetText(0, 0, 0, 19))) <> "NOTHING TO SCAN" '"SCAN FOR MORE DATA"
MsgBox "Data Extraction has been completed"
End Sub
I have the following code that does a screen scrape from Reflections - Attachmate and its not working.
The error I get is Compile Error - Variable not defined......screen shot attached.
It highlights this line of code.
Set Sessions = System.Sessions
Here is all the code...
Public Sub StartProcess()
Dim oSheet As Worksheet
Dim bIsStartDate As Boolean
Dim sMonth As String
Dim sBeginningValue As String
Dim sReceiptDate As String
Dim sMonthPremiumIsPayingFor As String
Dim sContributions As String
Dim sPremiumTax As String
Dim sAdminFee As String
Dim sCostofInsurance As String
Dim sDisbursement As String
Dim sInterest As String
Dim lRowIndexMF As Long
Dim lRowIndexXL As Long
Dim sTransCode As String
Dim sCheck As String
Dim iTransaction_year As Integer
Dim sPrevMonth As String
Dim sPrevCostofInsurance As String
Set Sessions = System.Sessions
Set oSheet = ActiveSheet
lRowIndexMF = 13
lRowIndexXL = START_ROW
If bIsStartDate = True Then
Else
oSheet.Range("k6").Value = "0"
End If
Do
sCheck = Trim(Session.GetText(lRowIndexMF, 0, lRowIndexMF, 80))
Select Case sCheck
Case "": GoTo NxtLine
Case Else:
If (InStr(sCheck, "COST") > 0) Or (Not (IsNumeric(VBA.Left(sCheck, 4)))) Then
GoTo NxtLine
End If
End Select
lRowIndexXL = lRowIndexXL + 1
'Read Values
sMonth = Session.GetText(lRowIndexMF, 76, lRowIndexMF, 80)
'sBeginningValue = Session.GetText(lRowIndexMF, 1, lRowIndexMF, 6)
sReceiptDate = Session.GetText(lRowIndexMF, 0, lRowIndexMF, 4)
sMonthPremiumIsPayingFor = Session.GetText(lRowIndexMF, 12, lRowIndexMF, 14)
'sMonthPremiumIsPayingFor = Session.GetText(lRowIndexMF, 6, lRowIndexMF, 10)
sContributions = Trim(Session.GetText(lRowIndexMF, 26, lRowIndexMF, 35))
'On Error Resume Next
If Trim(sContributions) <> "" Then
sContributions = IIf(Right(Trim(sContributions), 1) = "-", -Mid(Trim(sContributions), 1, Len(Trim(sContributions)) - 1), Trim(sContributions))
End If
'On Error GoTo 0
sPremiumTax = Trim(Session.GetText(lRowIndexMF, 36, lRowIndexMF, 43))
If Len(Trim(sPremiumTax)) > 0 Then
sPremiumTax = IIf(Right(Trim(sPremiumTax), 1) = "-", -Mid(Trim(sPremiumTax), 1, Len(Trim(sPremiumTax)) - 1), Trim(sPremiumTax))
End If
sAdminFee = Trim(Session.GetText(lRowIndexMF, 44, lRowIndexMF, 49))
sCostofInsurance = Trim(Session.GetText(lRowIndexMF, 50, lRowIndexMF, 58))
sDisbursement = 0 'Session.GetText(lRowIndexMF, 1, lRowIndexMF, 6)
sInterest = Trim(Session.GetText(lRowIndexMF, 59, lRowIndexMF, 67))
sTransCode = Session.GetText(lRowIndexMF, 16, lRowIndexMF, 17)
'Debug.Print Format(VBA.Right(sMonth, 2) & "/01/" & VBA.Left(sMonth, 2), "mmm")
'Update Excel
If sMonth = "0000" Then
If lRowIndexXL = START_ROW Then
oSheet.Range("A" & lRowIndexXL).Value = "ERROR"
'sMonth = "ERROR"
GoTo NxtEntry
Else
'oSheet.Range("A" & lRowIndexXL).Value = oSheet.Range("A" & lRowIndexXL - 1).Value
sMonth = Format(oSheet.Range("A" & lRowIndexXL - 1).Value, "yy") & Format(oSheet.Range("A" & lRowIndexXL - 1).Value, "mm")
End If
End If
oSheet.Range("A" & lRowIndexXL).Select
oSheet.Range("A" & lRowIndexXL).Value = "'" & Format(VBA.Right(sMonth, 2) & "/01/" & VBA.Left(sMonth, 2), "mmm") & "-" & Format(VBA.Right(sMonth, 2) & "/01/" & VBA.Left(sMonth, 2), "yy")
NxtEntry:
'oSheet.Range("B" & lRowIndexXL).Value = sBeginningValue
'oSheet.Range("C" & lRowIndexXL).Value = Format(VBA.Mid(sReceiptDate, 2, 2) & "/" & VBA.Right(sReceiptDate, 2) & "/" & VBA.Left(sMonth, 2), "mm/dd/yyyy")
'oSheet.Range("D" & lRowIndexXL).Value = "'" & Format(VBA.Right(sMonthPremiumIsPayingFor, 2) & "/01/" & VBA.Left(sMonth, 2), "mmm") & "-" & Format(VBA.Right(sMonthPremiumIsPayingFor, 2) & "/01/" & VBA.Left(sMonth, 2), "yy")
oSheet.Range("C" & lRowIndexXL).Value = Format(VBA.Mid(sReceiptDate, 2, 2) & "/" & VBA.Right(sReceiptDate, 2) & "/" & GetTransactionYear(sMonth, sReceiptDate), "mm/dd/yyyy")
oSheet.Range("D" & lRowIndexXL).Value = "'" & Format(VBA.Right(sMonthPremiumIsPayingFor, 2) & "/01/" & VBA.Left(sMonth, 2), "mmm") & "-" & Format(VBA.Right(sMonthPremiumIsPayingFor, 2) & "/01/" & GetTransactionYear(sMonth, sMonthPremiumIsPayingFor), "yy")
oSheet.Range("E" & lRowIndexXL).Value = sContributions
oSheet.Range("F" & lRowIndexXL).Value = IIf(sPremiumTax = "", 0, -Val(sPremiumTax))
oSheet.Range("G" & lRowIndexXL).Value = IIf(sAdminFee = "", sAdminFee, -Val(sAdminFee))
If InStr(sCostofInsurance, ".") > 0 Then
oSheet.Range("H" & lRowIndexXL).Value = -sCostofInsurance
Else
oSheet.Range("H" & lRowIndexXL).Value = oSheet.Range("H" & lRowIndexXL - 1).Value
End If
If sPrevMonth = sMonth Then
If InStr(sPrevCostofInsurance, ".") = 0 Then
oSheet.Range("H" & lRowIndexXL).Value = 0
End If
End If
Select Case sTransCode
Case "31", "32", "34", "37":
sDisbursement = sContributions
oSheet.Range("E" & lRowIndexXL).Value = "0"
Case "05"
oSheet.Range("E" & lRowIndexXL).Value = "0"
End Select
oSheet.Range("I" & lRowIndexXL).Value = sDisbursement
oSheet.Range("J" & lRowIndexXL).Value = sInterest
sPrevMonth = sMonth
sPrevCostofInsurance = sCostofInsurance
Call EnterFormulas(lRowIndexXL, oSheet)
NxtLine:
If lRowIndexMF = 24 Then
lRowIndexMF = 13
'next page
Session.TransmitTerminalKey (rcHpF4Key)
Application.Wait (Now + TimeValue("00:00:02"))
Else
lRowIndexMF = lRowIndexMF + 1
End If
Loop While VBA.Trim((Session.GetText(0, 0, 0, 19))) <> "NOTHING TO SCAN" '"SCAN FOR MORE DATA"
MsgBox "Data Extraction has been completed"
End Sub