4 Replies Latest reply: Jun 13, 2012 4:50 AM by John Loria RSS

How create SAPlogon with Visual Script?

John Loria
Currently Being Moderated

Hello, I am trying to create a SAP GUI instance for access any box in the SAP. I am using SAP Scripting with Visual Basic, but when I run the scritp, it show me the following message:

 

"ActiveX xomponent can´t create object: 'Sapgui.ScriptingCtrl.1'"

 

I want to check some chains automatically using SAPScript, I have not problem while SAP GUI instance is running, I can log inside the differents boxes, but I want to execute the SAP GUI instance in the script directly.

 

This is a scritp example to I found in somewhere in the internet:

 

set LogonControl = CreateObject ( " SAP.LogonControl.1 " )

set conn = LogonControl.NewConnection

 

if conn.Logon (0, True) <> True then

                MsgBox " Cannot log on! "

End If

 

Please, someone Can I teach me? How do it?  or which is the error?

  • Re: How create SAPlogon with Visual Script?
    Shambu VS
    Currently Being Moderated

    Go to VB Editor, Select References in tool menu, and make sure these references are checked.

    Visual Basic for Applications

    Microsoft Excel 12.0 Object Library  (If 12.0 is not there, Select latest eg: 11.0)

    OLE Automation

    Microsoft Office 12.0 Object Library   (If 12.0 is not there, Select latest eg: 11.0)

     

    Thanks,

    Shambu

    • Re: How create SAPlogon with Visual Script?
      John Loria
      Currently Being Moderated

      Hello Shambu, thanks for as soon answer.  I checked the References and I found activated following:

       

      -Visual Basic for Applications

      -Microsoft Excel 14.0 Object Library

      -OLE Automation

      -Microsoft Office 14.0 Object Library

       

      I am not a SAP developer, but I am learning how create scripts, I saw another examples how is possible to do the I want to do, but when I run it in my machine do not work.

       

       

      I am using SAP NetWeaver 720 Final Release in Windows 7, has syntax changed?

  • Re: How create SAPlogon with Visual Script?
    Sandra Rossi
    Currently Being Moderated

    Hi,

     

    1) I don't understand what you exactly want to achieve with SAP GUI scripting: is it (A) how to log in and execute actions automatically, or (B) how to execute actions only, on an already manually opened session?

     

    2) It's difficult to help if we don't know your code. With the message you have (you can also check internet), the only thing I could deduce is that the OCX is not correctly registered in Windows.

     

    3) The code you mention (SAP.logonControl.1) is a way to log in SAP, but is more oriented to execute RFCs... There's another way to log in through SAP GUI scripting.

     

    4) Note: the term "SAPscript" (an obsolete text and printout layout technology) is not related to "SAP GUI scripting" in any way.

     

    5) I'm not sure, but I'm not quite aware of how all this works exactly, Shambu's answer is really about the message "ActiveX component can´t create object: 'Sapgui.ScriptingCtrl.1'": I think the "references" mentioned here are needed only for using "early binding" (see wikipedia; it's opposed to "late binding" that you probably (?) use in your code, i.e. CreateObject or GetObject method). For SAP GUI Scripting, the reference you should add to use early binding is \Program Files\SAP\FrontEnd\SAPgui\sapfewse.ocx.

     

    Regards

    Sandra

    • Re: How create SAPlogon with Visual Script?
      John Loria
      Currently Being Moderated

      Hello Sandra, many thanks for your answer and sorry for respond late. I understand very much better now, and the above answers have helped me for I can improve my script.

       

       

      The problem was that I was executing the script in a visual basic file, not into the excel file, and when I tried to executed the script,  the SAP session was not running but if I executed the script into the excel file then there was not problem.

       

       

      So what was happening was that the SAP library reference did not exist when I executed the script outside excel.

       

       

      So for to finish, all the problem was for my little experience programing the SAP

       

       

      Many thanks!!

Actions