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

To report this post you need to login first.

8 Comments

You must be Logged on to comment or reply to a post.

    1. Stefan Schnell Post author

      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

      (0) 
  1. Andrea Pugolotti

    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

    (0) 
  2. Stefan Schnell Post author

    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

    (1) 
    1. Andrea Pugolotti

      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

      (1) 
        1. Andrea Pugolotti

           

          Hello Stefan,

          last question: were you able to work with 64 bit? Did the REGEDIT trick work with you?

          If yes, please, could you report how?

           

          Thanks and best regards

          Davide

          (0) 

Leave a Reply