Error: Expected End of Statement RRS feed

  • Question

  • Hello,

    Please help, I am doing a COA printing using QC22 by Sap Gui Scripting.

    I'm not yet good in vbs. below is my recording and having an error: Expected End of Statement.

    Kindly correct what is the missing and error of below codes. Thank you so much.

    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 As Excel.Application

    Dim objSheet, intRow, i

    Set objExcel = GetObject(,"C:\TEMP\COA\Book1.xlsx")

    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

    cOL3 = Trim(CStr(objSheet.Cells(i, 3).Value)) 'Column3

    session.findById("wnd[0]/tbar[0]/okcd").text = "/nqc22"
    session.findById("wnd[0]/usr/ctxtP_MATNR").text = cOL1
    session.findById("wnd[0]/usr/ctxtP_CHARG").text = cOL2
    session.findById("wnd[0]/usr/ctxtP_WERKS").text = cOL3
    session.findById("wnd[0]/usr/ctxtP_WERKS").caretPosition = 4
    session.findById("wnd[0]/usr/cmbP_MEDIUM").key = "1"


    MsgBox = "The certificate was created."

    End IF

    Saturday, February 3, 2018 3:41 PM


  • The following is wrong:

    MsgBox = "The certificate was created."

    Remove the "="

    MsgBox "The certificate was created."


    Saturday, February 3, 2018 5:31 PM

All replies

  • That error often is seen when you have unbalanced quotes.

    Edit: The error message will include a line number in the script, that will help troubleshoot.

    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Saturday, February 3, 2018 3:50 PM
  • The following is wrong:

    MsgBox = "The certificate was created."

    Remove the "="

    MsgBox "The certificate was created."


    Saturday, February 3, 2018 5:31 PM
  • Hi, I tried but the same error displayed. Please help again. Thanks a lot.
    Sunday, February 4, 2018 4:47 AM
  • Hi, thanks for the advise but can you please provide the exact code that I need to input? Sorry I'm not so good in coding. Pls. Thanks  a lot.
    Sunday, February 4, 2018 4:50 AM
  • I did.  The second line is the correct code.


    Sunday, February 4, 2018 6:02 AM
  • Thanks you so much. Its already working fine :)
    Wednesday, February 7, 2018 10:04 AM