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