Skip to Content
0
Former Member
Mar 28, 2017 at 07:18 AM

Excel to SAP Using VBscript - Invalid Character error

1234 Views

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 Mariano Cabalen 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[0]/tbar[0]/okcd").text = "/npfcg"
	session.findById("wnd[0]").sendVKey 0
	session.findById("wnd[0]/usr/ctxtAGR_NAME_NEU").text = COL1
	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 = COL2
	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
next
msgbox “Process Completed”


Set objSheet = Nothing
objWrkbk.close
Set objWrkbk = Nothing
objExcel.close
Set objExcel = Nothing

Thanks in advance!

-Bagani

Attachments

2.png (37.5 kB)
error-sap-1.png (6.1 kB)
3.png (7.9 kB)