Skip to Content
avatar image
Former Member

Invalid character error in SAP Scripting and playback

Hi ,

I am trying to play the .vbs script for VA42, but getting an error as

Please find my code below:

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


Dim objExcel
Dim objSheet, intRow, i
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
COL2 = Trim(CStr(objSheet.Cells(i, 2).Value)) ‘Column2


session.findById("wnd[0]/tbar[0]/okcd").text = "/nva42"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtVBAK-VBELN").text = COL1
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\01/ssubSUBSCREEN_BODY:SAPMV45A:4426/subSUBSCREEN_TC:SAPMV45A:4908/tblSAPMV45ATCTRL_U_ERF_KONTRAKT/txtVBAP-ARKTX[4,0]").setFocus
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\01/ssubSUBSCREEN_BODY:SAPMV45A:4426/subSUBSCREEN_TC:SAPMV45A:4908/tblSAPMV45ATCTRL_U_ERF_KONTRAKT/txtVBAP-ARKTX[4,0]").caretPosition = 10
session.findById("wnd[0]").sendVKey 2
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\06").select
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP/tabpT\06/ssubSUBSCREEN_BODY:SAPLV60F:4201/ctxtFPLA-LODAT").text = COL2
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[0]/btn[3]").press
session.findById("wnd[0]/tbar[0]/btn[11]").press


aux=col1 & ” ” & col2
CreateObject(“WScript.Shell”).run(“cmd /c @echo %date% %time% ” & aux & ” >> C:\SCRIPT\PlOrCreationLog.txt”)
next
msgbox “Process Completed”
capture.png (4.8 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Mar 27, 2017 at 08:36 PM

    Hello Rajesh,

    as far as I can see you use

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

    instead of

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

    The double quotes are not correct.

    Also the comment signs, for example here

    COL1 = Trim(CStr(objSheet.Cells(i, 1).Value)) ‘Column1

    instead of

    COL1 = Trim(CStr(objSheet.Cells(i, 1).Value)) 'Column1

    Replace all these characters in your code and it should run without invalid character error.

    I try it on my system and it works with the changes above.

    Let us know your result.

    Cheers
    Stefan

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 23, 2017 at 11:06 PM

    Thank you very much, you just solved my problem.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 12, 2017 at 01:02 PM

    Great! Thank you very much!

    Add comment
    10|10000 characters needed characters exceeded