Skip to Content
0
Dec 02, 2011 at 11:22 AM

Skipping errors in WBS elements closure with a SAP / Excel script.

99 Views

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