VBA - SAP Scripting ErrorHandling

hsyntknlp

New Member
Joined
May 20, 2019
Messages
1
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.

Xsd7YGL
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
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,214,392
Messages
6,119,257
Members
448,880
Latest member
aveternik

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top