Hi everybody,
my question is regarding with error handling in VBA on SAP Scripting.
below you may see the my codes (which is not working properly)
I have tried many times to make it better but unfortunately I am failed
Shortly i would like to change the date of order in sap based on the excel new date copy previous date into the excel(existed delivery date)
May I ask your help to dig it better to know it ?
your help will be highly appreciated, thank you in advance.
my question is regarding with error handling in VBA on SAP Scripting.
below you may see the my codes (which is not working properly)
I have tried many times to make it better but unfortunately I am failed
Shortly i would like to change the date of order in sap based on the excel new date copy previous date into the excel(existed delivery date)
May I ask your help to dig it better to know it ?
your help will be highly appreciated, thank you in advance.
Code:
Sub extractingPOOADataScriptd()
Dim excelApp As Application
Dim excelWb As ThisWorkbook
Dim scriptWs As Worksheet
Dim scriptData As Range
Dim scriptRow As Range
Dim session As Object
Dim system As String
Dim documentNumber As String
Dim item As String
Dim cell As Variant
Set excelApp = Application
Set excelWb = excelApp.ThisWorkbook
Set scriptWs = excelWb.Sheets("Raw Data")
Set scriptData = scriptWs.Range("A1").CurrentRegion
Set scriptData = scriptData.Offset(1, 0).Resize(scriptData.Rows.Count - 1, scriptData.Columns.Count)
excelApp.ScreenUpdating = False
excelApp.ScreenUpdating = True
On Error Resume Next
Set session = connectToOpenSAPSession
session.findById("wnd[0]/tbar[0]/okcd").Text = "/nme23n"
session.findById("wnd[0]").sendVKey 0
For Each scriptRow In scriptData.Rows
checking = scriptRow.Resize(1, 1).Offset(0, 7).Value
documentNumber = scriptRow.Resize(1, 1).Value
item = scriptRow.Resize(1, 1).Offset(0, 1).Value
NewDate = scriptRow.Resize(1, 1).Offset(0, 2).Value
If Right(item, 1) = "0" Then item = Left(item, Len(item) - 1)
If Len(item) = 1 Then item = item
If Len(item) = 2 Then item = item
If Len(item) = 3 Then item = item
item = item - 1
If documentNumber <> "" Then
session.findById("wnd[0]/tbar[1]/btn[17]").press
session.findById("wnd[1]/usr/subSUB0:SAPLMEGUI:0003/ctxtMEPO_SELECT-EBELN").Text = documentNumber
session.findById("wnd[1]/tbar[0]/btn[0]").press
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject Application, "on"
End If
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[1]/btn[7]").press
scriptRow.Resize(1, 1).Offset(0, 6).Value = session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-EEIND[9," & item & "]").Text
If Err.Number <> 0 Then
scriptRow.Resize(1, 1).Offset(0, 6).Value = session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-EEIND[9," & item & "]").Text
scriptRow.Resize(1, 1).Offset(0, 7).Value = "Please check it to be ensure about changing."
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-EEIND[9," & item & "]").Text = NewDate
session.findById("wnd[0]/tbar[1]/btn[7]").press
Else
session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0013/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/ctxtMEPO1211-EEIND[9," & item & "]").Text = NewDate
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 0
scriptRow.Resize(1, 1).Offset(0, 7).Value = "date is updated"
session.findById("wnd[0]/tbar[1]/btn[7]").press
session.findById("wnd[1]/usr/btnSPOP-OPTION1").press
End If
End If
Next scriptRow
excelApp.ScreenUpdating = True
excelApp.ScreenUpdating = True
End Sub