Skip to Content

Use Named References of SAP ActiveX Libraries in VBA for Easy Programming

Hello community,

many Microsoft Office programmers uses the SAP ActiveX libraries of the SAP GUI for Windows installation. The reason for this descision is the availability of the libraries. To use the libraries it is necessary to reference it.

Menu Tools > References

/wp-content/uploads/2015/09/101_792733.jpg

Browse > Add Reference

/wp-content/uploads/2015/09/102_792755.jpg

It is necessary to add wdtfuncs.ocx, wdttaocx.ocx, wdtlog.ocx and optional wdobapi.ocx. You can find the files in the directory of the SAP GUI, C:\Program Files (x86)\SAP\FrontEnd\sapgui.

 

103.JPG

Hint: The wdtlog.ocx is in the directory C:\Program Files (x86)\Common Files\SAP Shared.

 

Hint: You can also use the unicode versions of the libraries, the filenames ends with an u.

/wp-content/uploads/2015/09/104_792757.jpg

So far the prelude. You can find a very good equivalent description here.

But many Office programmers declare their object variables in VBA only as Object. If they choose this method is it at first not necessary to reference the libraries and on second they lose the very good code completion functionality.

'-Begin-----------------------------------------------------------------
  Sub Test()

    '-Variables---------------------------------------------------------
      Dim oFunc As Object
      Dim oConn As Object
      Dim SAPConn As Integer

    Set oFunc = CreateObject("SAP.Functions.Unicode")
    If Not IsObject(oFunc) Then
       MsgBox "CreateObject(SAP.Functions.Unicode) failed", vbOKOnly, _
         "Error"
       Exit Sub
    End If

    Set oConn = oFunc.Connection()
    If Not IsObject(oConn) Then
      MsgBox "SAPFunc.Connection failed", vbOKOnly, "Error"
      Exit Sub
    End If

    SAPConn = oConn.Logon(0, vbFalse)
    If SAPConn <> 0 Then

      oConn.Logoff
    Else
      MsgBox "Connection.Logon failed", vbOKOnly, "Error"
    End If

  End Sub

'-End-------------------------------------------------------------------

 

If you want to benefit from the advantages, is it necessary to change the source like this:

'-Begin-----------------------------------------------------------------
  Sub Test()

    '-Variables---------------------------------------------------------
      Dim oFunc As SAPFunctionsOCX.SAPFunctions
      Dim oConn As SAPLogonCtrl.Connection
      Dim SAPConn As Integer

    Set oFunc = CreateObject("SAP.Functions.Unicode")
    If Not IsObject(oFunc) Then
       MsgBox "CreateObject(SAP.Functions.Unicode) failed", vbOKOnly, _
         "Error"
       Exit Sub
    End If

    Set oConn = oFunc.Connection()
    If Not IsObject(oConn) Then
      MsgBox "SAPFunc.Connection failed", vbOKOnly, "Error"
      Exit Sub
    End If

    SAPConn = oConn.Logon(0, vbFalse)
    If SAPConn <> 0 Then

      oConn.Logoff
    Else
      MsgBox "Connection.Logon failed", vbOKOnly, "Error"
    End If

  End Sub

'-End-------------------------------------------------------------------

 

As you can see is the source equivalent but the declarations of the variables oFunc and oConn are now not longer Objects, they are now definitive types from the library. And now the VBA IDE offers the code completion.

 

/wp-content/uploads/2015/09/105_792807.jpg

If you reference the SAP ActiveX libraries you should also declare your variables with the correct types, otherwise it makes no sense.

 

Hint: You can find information how to use SAP ActiveX libraries without SAP GUI for Windows here.

Cheers
Stefan

10 Comments
You must be Logged on to comment or reply to a post.
    • Hello Ziv,

      thanks for your reply.

      Unfortunately I don’t know more details. The support of the classic RFC SDK or the classic RFC library ends on March 31, 2016 and the ActiveX libraries are their appendix. I think this doesn’t mean stop shipping. We will see…

      Cheers

      Stefan

  • Dear Stefan,

    many very interesting articles by your side.

    A question concerning 32bit SAPGUI vs 64bit Excel: how is it possibile that on some PCs (7.40 with patch 10, Excel 2016) it works without problems (and without add ocx controls to VBA) while on other PCs (7.40 with patch 12, Excel 2010) it doesn’t?

    Problem is the usual run-time error ‘429’: ActiveX cannot create the object (Set oFunc = CreateObject(“SAP.Functions.Unicode”)).

    I’ve tried the solution of REGEDIT extension with DllSurrogate (

    https://archive.sap.com/discussions/thread/3505080) but nothing’s changed.

     

    Thanks and best regards

    Davide

  • Hello Davide,

    thanks for your reply.

    As far as I under stand you correct: You have PCs with SAP GUI 7.40 PL 10 and Excel 2016 x64 with an VBA program which runs without problems, without any modification of the registry.  And you have PCs with SAP GUI 7.40 PL 12 and Excel 2010 x64 and the same VBA programs don’t run, also without any modification of the registry.

    As far as I know it isn’t possible to instanciate one of the ActiveX components with an x64 application with the standard SAP GUI installation. But I don’t know it exactly with the actual patch levels, because it checked it with an older one.

    To validate this I check it actual with AutoIt x86 and x64, because I don’t have Excel x64:

    ;-Begin-----------------------------------------------------------------
    
      $oFunc = ObjCreate("SAP.Functions.Unicode")
      If IsObj($oFunc) Then
        MsgBox(0, "", "Create object SAP.Functions.Unicode")
        $oFunc = 0
      Else
        MsgBox(0, "", "Can't create object SAP.Functions.Unicode")
      EndIf
    
    ;-End-------------------------------------------------------------------

    The x86 version creates the object and the x64 version don’t, as I expected – with SAP GUI for Windows 7.40 PL 7. It is possible that the installation program of the SAP GUI for Windows is changed from PL 7 to PL 10 resp. PL 12.

    Cheers
    Stefan

    • Dear Stefan,

      thanks for your prompt reply. In fact, what I thought was wrong.. Yesterdey evening I’ve realized that my home PC runs Office 365 with Excel 2016 32 bit. This explains the fact that SAP function works with VBA without any problem.

      Different question is my work PC that runs Excel 2016 64 bit and, as told, neither with REGEDIT adjustments it works. Therefore, probably, my work on REGEDIT hasen’t been performed as suggested.

      Anyway, I saw a very impressive demo of Winshuttle that proves everything is possibile with VBA (Excel) vs SAP.

      Thanks and best regards

      Davide

  • Hi Stefan,

    I am new to VB Scripting I am working towards uploading an excel to SAP and execute a RFC.
    This Excel is working as expected in a Windows 7, but not working on Windows 10.

    The Windows 10 system is a 64 bit processor, Excel is also 64 bit and VBA is also running on 64 bit processor.

    In addition to the above mentioned libraries, I am using sapfewse.ocx (SAP GUI Scripting API), yet I am getting “Run-time error ‘429’: ActiveX component create object” Error, for any createobject statements such as below

    1. Set objBAPIControl = CreateObject(“SAP.Functions”)
    2. Set LogonControl = CreateObject(“SAP.LogonControl.1”)
    3. Set Functions = CreateObject(“SAP.Functions”)
    4. Set TableFactory = CreateObject(“SAP.TableFactory.1”)
    5. Set objConnection = LogonControl.NewConnection

    Please advise, how I can avoid this error and proceed further.

    Thanks,

    Swathi

    • Hello Swathi,

      you can take a little test. Here at first a VBScript, save it as Test.vbs:

      '-Begin-----------------------------------------------------------------
      
      '-Sub Main--------------------------------------------------------------
      Sub Main
      
        On Error Resume Next
        Set oFunc = CreateObject("SAP.Functions.Unicode")
        On Error Goto 0
        If Not IsObject(oFunc) Then
          MsgBox "CreateObject(SAP.Functions.Unicode) failed", vbOKOnly, "Error"
      	Exit Sub
        End If
      
        Set oFunc = Nothing
      End Sub
      
      '-Main------------------------------------------------------------------
      Main
      
      '-End-------------------------------------------------------------------

      Execute it with the following command line

      C:\Windows\System32\wscript.exe Test.vbs

      and you get this message

      Execute it with the following command line

      C:\Windows\SysWOW64\wscript.exe Test.vbs

      it works.

      The difference here is, the first call is x64 and the second is x86. SAP ActiveX components don’t work in x64 environments.

      Best regards
      Stefan