Avalados por :

Automatización de creación de roles en SAP utilizando VBscript y Excel: Guía paso a paso

  • Creado 01/03/2024
  • Modificado 01/03/2024
  • 10 Vistas
0
Cargando...

Hi Experts,

My purpose is to utilize VBscript to automatically create multiple roles (via transaction PFCG) based on an Excel input.

I recently found out about VBscript for SAP so I'm not that good in VB coding yet.

I have followed this tutorial, credits to marianoc for this:

Anyway, I've already recorded the process, and my excel file (which contains only two columns) is ready.

When I press the play button:

I encounter this error:

My question is, what could be the cause of this error? I'm sure this is not a syntax problem as I've religiously followed the guidelines of the tutorial.

Attaching the code here:

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

Set objExcel = GetObject(,”Excel.Application) 
Set objWrkbk = objExcel.OpenWorkbook("C:\Users\sularte\Downloads\Test_Role_Creation.xlsx")
Set objSheet = Sheets("Sheet1") 

For i = 2 to objSheet.UsedRange.Rows.Count 
   session.findById("wnd[
                
                
Pedro Pascal
Se unió el 07/03/2018
Pinterest
Telegram
Linkedin
Whatsapp

2 Respuestas

0
Cargando...

¡Hola!

No soy un experto en SAP, pero al igual que tú, he intentado trabajar con el código publicado por Mariano pero no pude, el mismo error aparece...

Después de unas horas buscando en Google... encontré este código en SlideShare, combiné y adapté ambos

Ahora está funcionando para mí (en un TCODE diferente)

Aquí copiaré y pegaré tu código con las modificaciones, prueba con esto y espero que sea útil

Saludos

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

Dim objExcel,objWorkbook
Dim objSheet, intRow, i
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.open ("C:\Users\sularte\Downloads\Test_Role_Creation.xlsx")
Set objSheet = objExcel.Worksheets(1)
Row = 2

session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "/npfcg"
session.findById("wnd[0]").sendVKey 0

Do Until objSheet.cells(Row,1).value=""

session.findById("wnd[0]/usr/ctxtAGR_NAME_NEU").text = objSheet.Cells(Row,1).Value
session.findById("wnd[0]/usr/ctxtAGR_NAME_NEU").caretPosition = 16
session.findById("wnd[0]/usr/btn%#AUTOTEXT003").press
session.findById("wnd[0]/usr/txtS_AGR_TEXTS-TEXT").text = objSheet.Cells(Row,2).Value
session.findById("wnd[0]/usr/txtS_AGR_TEXTS-TEXT").caretPosition = 9
session.findById("wnd[0]").sendVKey 11
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB9").select
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB9/ssubSUB1:SAPLPRGN_TREE:0321/cntlTOOL_CONTROL/shellcont/shell").pressButton "TB03"
session.findById("wnd[1]/usr/tblSAPLPRGN_WIZARDCTRL_TCODE/ctxtS_TCODES-TCODE[0,0]").text = "su01d"
session.findById("wnd[1]/usr/tblSAPLPRGN_WIZARDCTRL_TCODE/ctxtS_TCODES-TCODE[0,0]").caretPosition = 5
session.findById("wnd[1]").sendVKey 0
session.findById("wnd[1]/tbar[0]/btn[19]").press
session.findById("wnd[0]").sendVKey 11
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB5").select
session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB5/ssubSUB1:SAPLPRGN_TREE:0350/btnEXPERTE").press
session.findById("wnd[0]/usr/lbl[5,5]").setFocus
session.findById("wnd[0]/usr/lbl[5,5]").caretPosition = 1
session.findById("wnd[0]").sendVKey 2
session.findById("wnd[0]/usr/lbl[32,2]").setFocus
session.findById("wnd[0]/usr/lbl[32,2]").caretPosition = 0
session.findById("wnd[0]").sendVKey 2
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]").sendVKey 11
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]/tbar[1]/btn[17]").press
session.findById("wnd[0]/tbar[0]/btn[3]").press
session.findById("wnd[0]/tbar[0]/btn[3]").press

Row = Row + 1
Loop
objExcel.Quit
Set objExcel = Nothing
Set objWorkbook = Nothing
Set objSheet = Nothing
msgbox ("Proceso completado")

Respondido el 15/04/2024
LUCIANO RIOJA GHIOTTO
Se unió el 13/07/2019
0
Cargando...

Hola,

En el tutorial mencionas que hay dos bloques de código que deben ser colocados en tu script.

No veo estas líneas en tu código. Revisa el tutorial y busca por ejemplo "Bloque de código: Bloque A"

Saludos cordiales,

Bernhard

Respondido el 15/04/2024
LUCIANO RIOJA GHIOTTO
Se unió el 13/07/2019

contacto@primeinstitute.com

(+51) 1641 9379
(+57) 1489 6964

© 2024 Copyright. Todos los derechos reservados.

Desarrollado por Prime Institute

¡Hola! Soy Diana, asesora académica de Prime Institute, indícame en que curso estas interesado, saludos!
Hola ¿Puedo ayudarte?