on 11-26-2007 3:13 PM
Hi folks,
I am quite new to VBscripting and trying to create a script that automatically mass generates users via SU01.
Everything worked fine so far but now I am stuck because of a stupid popup.
If a user was created and afterwards deleted and I am going to recreate it, SAP will ask me if I want to use his old office data.
If it does my script gets stuck of course because it wants to continue to supply the user details.
Please have a look at the code (problem is
bold
😞Dim strFilename, Dialog, fso, conentTextfile
Dim Test
Set Dialog = CreateObject("MSComDlg.CommonDialog")
Set fsobj = CreateObject("Scripting.FileSystemObject")
'Explorer-Dialog zum Öffnen von Dateien
'Titelzeile
Dialog.DialogTitle = "Datei öffnen"
'Suchmaske (hier benutzerdefiniertes Dateikürzel)
Dialog.Filter = "Textdateien-Datei (.txt)|.txt"
'Filterindex
Dialog.FilterIndex = 1
Dialog.MaxFileSize = 260
'Flags setzen: Explorer-Dialog mit langen Dateinamen
Dialog.Flags = &H1814
'Datei öffnen
Dialog.ShowOpen
'Ergebnis der Dateianwahl ausgeben
strFilename = Dialog.Filename
If strFilename <> "" Then
Set textfile = fsobj.OpenTextFile(strFilename,"1")
do while not textfile.AtEndOfStream
'Zeilen einzeln einlesen
TextLine = textfile.ReadLine
UserData = Split(TextLine,",")
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
End If
If Not IsObject(session) Then
Set session = connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"
End If
session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/ctxtUSR02-BNAME").text = UserData(0)
session.findById("wnd[0]/usr/ctxtUSR02-BNAME").caretPosition = 7
session.findById("wnd[0]/tbar[1]/btn[8]").press
'Here is the problem!!!
Test = session.findById("wnd[1]").Type
if test = "GuiModalWindow" then
session.findById("wnd[1]/usr/btnBUTTON_1").press
end if
'If I check for the popup window (as shown above) and the user didn't exist before (so there is no popup window) the program will exit with an exception because wnd[1] doesn't exist. Is there any possibility to check wether wnd[1] exists?
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSZA5:0900/txtADDR3_DATA-NAME_LAST").text = UserData(1)
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSZA5:0900/txtADDR3_DATA-NAME_FIRST").text = UserData(2)
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSZA5:0900/txtADDR3_DATA-NAME_FIRST").setFocus
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSZA5:0900/txtADDR3_DATA-NAME_FIRST").caretPosition = 10
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO").select
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUU5:0101/pwdG_PASSWORD1").text = UserData(4)
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUU5:0101/pwdG_PASSWORD2").text = UserData(5)
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUU5:0101/ctxtUSLOGOND-CLASS").text = UserData(3)
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUU5:0101/ctxtUSLOGOND-GLTGV").text = UserData(6)
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUU5:0101/ctxtUSLOGOND-GLTGB").text = UserData(7)
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUU5:0101/ctxtUSLOGOND-GLTGB").setFocus
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUU5:0101/ctxtUSLOGOND-GLTGB").caretPosition = 10
session.findById("wnd[0]/tbar[0]/btn[11]").press
loop
End If
Set Dialog = Nothing
Set fso = Nothing
Thanks in advance and kind regards,
Bastian
Hi Bastian,
I also came across similar scenario need to handle unexpected popup. I have found a simple solution as below.
If Session.ActiveWindow.Name = "wnd[1]" Then
If Session.findbyid("wnd[1]").Text Like "Delete*" Then Session.findbyid("wnd[1]/usr/btnSPOP-OPTION1").press
End If
Hope it helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Bastian,
just as an additional reply.... check for "session.ActiveWindow.Type". You can distinguish "GuiMainWindow" and "GuiModalWindow". That's how you catch a popup the easiest way.
Cheers,
Werner
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
If it is an error in VB/VBA, you should work with errorhandlers. If it is an error (msgbox) in SAPGUI, then you should turn this off by:
Property messageAsPopup As Boolean (Read only)
Description: Some message may be displayed not only on the
statusbar but also as a pop-up window. In such
cases, this property is set to True so that a
script knows it has to close a pop-up continue.
Good Luck
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You can have error handling code to write the error in log and continue the program running. make On Error Resume Next statement in the beginning of the code.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.