Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
stefan_schnell
Active Contributor
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



Browse > Add Reference



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.

 



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.



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.

 



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.
11 Comments