Hi Dears,
I want to change confirmation key, and input confirmation automatically, but when I tried to run SAP script it always failed on this line.
This is to check if confirmation control is blank, if yes, then choice C001, some times PO line already has confirmation key, some times not.
And I always got problem when I try to choice confirmation label, some times it will failed as well.
Can some body help on this, many thanks in advance.
If Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB1:SAPLMEGUI:1334/cmbMEPO1334-BSTAE").Key = "" Then
Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB1:SAPLMEGUI:1334/cmbMEPO1334-BSTAE").Key = "C001"
Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB1:SAPLMEGUI:1334/cmbMEPO1334-BSTAE").SetFocus
Session.findById("wnd[0]").sendVKey 0
End If
Below is total script
Option Explicit
Public SapGuiAuto As Object, Applicat As Object, Connection As Object, Session As Object
Function Attach() As Boolean
On Error Resume Next
Set SapGuiAuto = GetObject("SAPGUI")
On Error GoTo 0
If SapGuiAuto Is Nothing Then
Attach = False
Exit Function
Else
Set Applicat = SapGuiAuto.GetScriptingEngine
On Error GoTo 0
End If
If Applicat Is Nothing Then
Attach = False
Exit Function
End If
If Applicat.Children.Count = 0 Then
Attach = False
Exit Function
Else
Set Connection = Applicat.Children(0)
On Error GoTo 0
End If
Set Session = Connection.Children(0)
If Session.ActiveWindow.Text = "SAP" Then
Attach = False
Exit Function
End If
Attach = True
End Function
Sub addABcon1025()
Dim i, PartNo, joblen, btt
Dim P
Dim Pline
Dim saptab
Dim POline, POnum, POdate, POqty
Application.DisplayAlerts = False
Application.EnableEvents = False
joblen = Sheet1.Cells(55555, 1).End(xlUp).Row
btt = Sheet1.Cells(55555, 4).End(xlUp).Row
If Attach Then
For PartNo = 2 To 10
'Range("d3:d9").ClearContents
Session.findById("wnd[0]").maximize
Session.findById("wnd[0]/tbar[0]/okcd").Text = "/nme22n"
Session.findById("wnd[0]").sendVKey 0
Session.findById("wnd[0]/tbar[1]/btn[17]").press
Session.findById("wnd[1]/usr/subSUB0:SAPLMEGUI:0003/ctxtMEPO_SELECT-EBELN").Text = Sheet1.Cells(PartNo, 4)
Session.findById("wnd[1]").sendVKey 0
''以上是改成我想要的PO,不用再做更改了
POdate = Sheet1.Cells(PartNo, 3)
POqty = Sheet1.Cells(PartNo, 10)
Pline = Sheet1.Cells(PartNo, 5) / 10
If Pline = 1 Then GoTo 10
If Pline < 10 Then
Sheet1.Cells(PartNo, 2) = "' " & Pline
Else
If Pline < 100 Then
Sheet1.Cells(PartNo, 2) = "' " & Pline
Else
If Pline < 1000 Then
Sheet1.Cells(PartNo, 2) = "' " & Pline
End If
End If
End If
Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB1:SAPLMEGUI:6000/cmbDYN_6000-LIST").SetFocus
Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB1:SAPLMEGUI:6000/cmbDYN_6000-LIST").Key = Sheet1.Cells(PartNo, 2) ''换成第二行
''以上是根据PO item更改行,如果没问题不要更改。
10 Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0015/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16").Select
''以上是选择Confirmation label,现在如果本来就是默认的这个label 就会报错.
If Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB1:SAPLMEGUI:1334/cmbMEPO1334-BSTAE").Key = "" Then
Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB1:SAPLMEGUI:1334/cmbMEPO1334-BSTAE").Key = "C001"
Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB1:SAPLMEGUI:1334/cmbMEPO1334-BSTAE").SetFocus
Session.findById("wnd[0]").sendVKey 0
End If
If Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB1:SAPLMEGUI:1334/cmbMEPO1334-BSTAE").Key = "" Then
Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB1:SAPLMEGUI:1334/cmbMEPO1334-BSTAE").Key = "C001"
Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB1:SAPLMEGUI:1334/cmbMEPO1334-BSTAE").SetFocus
Session.findById("wnd[0]").sendVKey 0
End If
''以上是更改confirmation key,如果为空就增加
Next PartNo
End If
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub
''update on1024,增加判断是否已经有AB的地方
If Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB2:SAPLMEGUI:1332/subSUB0:SAPLEINB:0300/tblSAPLEINBTC_0300/ctxtEKES-EBTYP[0,0]").Text = "" Then
Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB2:SAPLMEGUI:1332/subSUB0:SAPLEINB:0300/tblSAPLEINBTC_0300/ctxtEKES-EBTYP[0,0]").Text = "ab"
Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB2:SAPLMEGUI:1332/subSUB0:SAPLEINB:0300/tblSAPLEINBTC_0300/ctxtRM06E-EEIND[2,0]").Text = POdate
Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB2:SAPLMEGUI:1332/subSUB0:SAPLEINB:0300/tblSAPLEINBTC_0300/txtEKES-MENGE[4,0]").Text = POqty
Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB2:SAPLMEGUI:1332/subSUB0:SAPLEINB:0300/tblSAPLEINBTC_0300/txtEKES-MENGE[4,0]").SetFocus
Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT16/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB2:SAPLMEGUI:1332/subSUB0:SAPLEINB:0300/tblSAPLEINBTC_0300/txtEKES-MENGE[4,0]").caretPosition = 3
Session.findById("wnd[0]").sendVKey 0
Session.findById("wnd[0]").sendVKey 0
Session.findById("wnd[0]").sendVKey 0
Session.findById("wnd[0]/tbar[0]/btn[11]").press
Session.findById("wnd[1]/usr/btnSPOP-VAROPTION1").press
End If ''如果第一个AB code 写过了