on 12-02-2011 11:22 AM
Hai there!
I have a Excel / SAP macro for closing WBS elements in transaction CJ20N. This macro works fine until error messages occur (or warnings) in SAP because something was not completed on the WBS element.
So then I thought the macro may be able to skip the WBS element that has errors on it and continue trying to close the next one instead? And then make a little mark in my list of WBS elements to close. That would save loads of time.
Is this possible? This is what I have in the code right now.
WBSToClose = ActiveCell.Offset(0, 1).Value
session.findById("wnd[0]").maximize
session.findById("wnd[0]/shellcont/shellcont/shell/shellcont[1]/shell/shellcont[1]/shell").topNode = " 23"
session.findById("wnd[0]/shellcont/shellcont/shell/shellcont[0]/shell/shellcont[0]/shell").pressButton "OPEN"
session.findById("wnd[1]/usr/ctxtCNPB_W_ADD_OBJ_DYN-PRPS_EXT").Text = WBSToClose
session.findById("wnd[1]/usr/ctxtCNPB_W_ADD_OBJ_DYN-PRPS_EXT").SetFocus
session.findById("wnd[1]/usr/ctxtCNPB_W_ADD_OBJ_DYN-PRPS_EXT").caretPosition = 0
session.findById("wnd[1]").sendVKey 0
session.findById("wnd[0]/mbar/menu[1]/menu[1]/menu[6]/menu[0]").Select '<--- This is the close button, after this errors sometimes occur.
session.findById("wnd[0]/tbar[0]/btn[11]").press '<--- save button.
session.findById("wnd[0]/shellcont/shellcont/shell/shellcont[1]/shell/shellcont[1]/shell").topNode = " 23"
Below is an example of an error message popping up while trying to close.
session.findById("wnd[0]").maximize
session.findById("wnd[0]/shellcont/shellcont/shell/shellcont[1]/shell/shellcont[1]/shell").topNode = " 23"
session.findById("wnd[0]/shellcont/shellcont/shell/shellcont[0]/shell/shellcont[0]/shell").pressButton "OPEN"
session.findById("wnd[1]/usr/ctxtCNPB_W_ADD_OBJ_DYN-PRPS_EXT").text = WBSToClose
session.findById("wnd[1]/usr/ctxtCNPB_W_ADD_OBJ_DYN-PRPS_EXT").setFocus
session.findById("wnd[1]/usr/ctxtCNPB_W_ADD_OBJ_DYN-PRPS_EXT").caretPosition = 18
session.findById("wnd[1]").sendVKey 0
session.findById("wnd[0]/mbar/menu[1]/menu[1]/menu[6]/menu[0]").select '<--- Selecting close
session.findById("wnd[1]/usr/btnOPTION2").press '<--- Here I click "Continue" on the error message
session.findById("wnd[0]/tbar[0]/btn[3]").press '<--- Back button
session.findById("wnd[0]/shellcont/shellcont/shell/shellcont[1]/shell/shellcont[1]/shell").topNode = " 23"
I would also like the script to put a little mark in my excel file showing which WBS elements that had errors on them. Just a number or so. But thats a bonus.
Is this possible?
Thanks, Mattias
Hi Mattias,
You could try the following:
. . .
Row = 2
Column = 1
. . .
WBSToClose = ActiveCell.Offset(0, 1).Value
session.findById("wnd[0]").maximize
session.findById("wnd[0]/shellcont/shellcont/shell/shellcont[1]/shell/shellcont[1]/shell").topNode = " 23"
session.findById("wnd[0]/shellcont/shellcont/shell/shellcont[0]/shell/shellcont[0]/shell").pressButton "OPEN"
session.findById("wnd[1]/usr/ctxtCNPB_W_ADD_OBJ_DYN-PRPS_EXT").text = WBSToClose
session.findById("wnd[1]/usr/ctxtCNPB_W_ADD_OBJ_DYN-PRPS_EXT").setFocus
'This command is redundant.
'session.findById("wnd[1]/usr/ctxtCNPB_W_ADD_OBJ_DYN-PRPS_EXT").caretPosition = 18
session.findById("wnd[1]").sendVKey 0
on error resume next
session.findById("wnd[0]/mbar/menu[1]/menu[1]/menu[6]/menu[0]").select '<--- Selecting close
session.findById("wnd[1]/usr/btnOPTION2").press '<--- Here I click "Continue" on the error message
if err.number = 0 then
'the button is available
Cells(Row, Column).Value = WBSToClose
end if
session.findById("wnd[0]/tbar[0]/btn[3]").press '<--- Back button
on error goto 0
session.findById("wnd[0]/shellcont/shellcont/shell/shellcont[1]/shell/shellcont[1]/shell").topNode = " 23"
Row = Row + 1
. . .
That should be just a little help for you.
Regards,
ScriptMan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello again!
Thanks alot! I got it to work perfectly with some modifications to the code.
Posting the solution in case someone can find it useful.
If (ActiveCell.Value = 0) Then
Row = 2
Column = 1
WBSToClose = ActiveCell.Offset(0, 1).Value
session.findById("wnd[0]").maximize
session.findById("wnd[0]/shellcont/shellcont/shell/shellcont[1]/shell/shellcont[1]/shell").topNode = " 23"
session.findById("wnd[0]/shellcont/shellcont/shell/shellcont[0]/shell/shellcont[0]/shell").pressButton "OPEN"
session.findById("wnd[1]/usr/ctxtCNPB_W_ADD_OBJ_DYN-PRPS_EXT").Text = WBSToClose
session.findById("wnd[1]/usr/ctxtCNPB_W_ADD_OBJ_DYN-PRPS_EXT").SetFocus
session.findById("wnd[1]").sendVKey 0
session.findById("wnd[0]/mbar/menu[1]/menu[1]/menu[6]/menu[0]").Select '<-- Selecting close
session.findById("wnd[0]/tbar[0]/btn[11]").press '<-- Save button.
On Error Resume Next
session.findById("wnd[1]").Close '<-- Close window button on any error message or warning
If Err.Number = 0 Then
ActiveCell.Value = 2
session.findById("wnd[0]/tbar[0]/btn[3]").press '<--- Back button if error message
End If
On Error GoTo 0
session.findById("wnd[0]/shellcont/shellcont/shell/shellcont[1]/shell/shellcont[1]/shell").topNode = " 23"
Row = Row + 1
End If
If ActiveCell.Value = 2 Then GoTo Fortsaett '<-- Skipping writing "1" in "processed"
ActiveCell.Value = 1
Fortsaett:
n = n + 1
ActiveCell.Offset(1, 0).Select
'Some looping hereafter
Points awarded.
Thanks, Mattias
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.