cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Script read from an Excel sheet recording and playback

leonidglik
Discoverer
0 Kudos

Hello Experts,

i am currently trying create a VBScript which is supose update a list of composite roles

with one set single role in pfcg.

The list should be stored in a simple Excel sheet containig only one column

However my mostly copied script is getting the error message "unallowed character"

What am i doing wrong?

Kind Regards

when i try to Playback the script

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

session.findById("wnd[0]").maximize

Set objExcel = GetObject(,”Excel.Application”) 
Set objSheet = objExcel.ActiveWorkbook.ActiveSheet

For i = 2 to objSheet.UsedRange.Rows.Count 
  COL1 = Trim(CStr(objSheet.Cells(i, 1).Value)) ‘Column1
  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/btn%#AUTOTEXT001").press
  session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB8").select
  session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB8/ssubSUB1:SAPLPRGN_TREE:0600/tblSAPLPRGN_TREECTRL_AGRLIST2/ctxtI_ACTGROUPS-AGR_NAME[0,0]").text = "T:TEST:S"
  session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB8/ssubSUB1:SAPLPRGN_TREE:0600/tblSAPLPRGN_TREECTRL_AGRLIST2/ctxtI_ACTGROUPS-AGR_NAME[0,0]").setFocus
  session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpTAB8/ssubSUB1:SAPLPRGN_TREE:0600/tblSAPLPRGN_TREECTRL_AGRLIST2/ctxtI_ACTGROUPS-AGR_NAME[0,0]").caretPosition = 8
  session.findById("wnd[0]").sendVKey 0
  session.findById("wnd[0]/tbar[0]/btn[11]").press
  aux=col1 
  CreateObject(“WScript.Shell”).run(“cmd /c @echo %date% %time% ” & aux & ” >> C:\Script\PlOrCreationLog.txt”)
next
msgbox “Process Completed”

stefan_schnell
Active Contributor
0 Kudos

Hello Leonid,

I have reformatted your code. But can you explain your error a little bit more please, do you have a line number where the error occurs?

Cheers
Stefan

Accepted Solutions (1)

Accepted Solutions (1)

stefan_schnell
Active Contributor
0 Kudos

Hello Leonid,

as far as I can see you use e.g. in the line msgBox not normal quotes:

msgbox “Process Completed”

instead of

msgbox "Process Completed"

Do you see the difference of the quotes? Instead of " you use “ and ”.

This is often a problem of copying and pasting source code.

Also in this line

Set objExcel = GetObject(,”Excel.Application”)

and that line

  CreateObject(“WScript.Shell”).run(“cmd /c @echo %date% %time% ” & aux & ” >> C:\Script\PlOrCreationLog.txt”)

Maybe this is the reason of the error. Please correct that and let us know your results.

Cheers
Stefan

leonidglik
Discoverer

Hello Stefan,

you are right on this one! It seems like i messed up the the code of the script file somehow while copy and paste bettween Notepad, Notepad++ and the sourcecode.

After converting into UTF-8 everything working correctly.

Thank you kindly

Leonid Glik

Answers (0)