VBA Example for Excel

This example code shows how to use the Visual RFC Service Provider with standard desktop applications (like MS Excel, etc.).

VBA Declarations of the Visual RFC Service Provider Management Functions

The following code shows the function declarations for Visual Basic (for Applications):

Option Explicit

Declare Function GetCurrentTask Lib "KERNEL.DLL" () As Integer

Declare Function GetActiveWindow Lib "USER.DLL" () As Integer

Declare Function RegisterVRFCService Lib "VRFC.DLL"
(ByVal AppName$, ByVal hIns%) As Integer
Declare Sub UnRegisterVRFCService Lib "VRFC.DLL"
(ByVal hAppl%)
Declare Function RequestVRFCLogon Lib "VRFC.DLL"
(ByVal hWnd As Integer, ByVal hAppl As Integer, ByVal c_mode As Integer, _
‘ all of the following parameters can be passed in with null values
ByVal destination As String, ByVal hostname As String, ByVal sysnr As Integer,_
ByVal gateway_host As String, ByVal gateway_service As String, ByVal client As String, _
ByVal user As String, ByVal password As String, ByVal language As String, _
ByVal trace As Integer, ByVal mode As Integer)
As Integer

Declare Function RequestVRFCADMConnections Lib "VRFC.DLL"
(ByVal hWnd As Integer, ByVal hAppl As Integer) As Integer

Declare Sub RequestVRFCLogoff Lib "VRFC.DLL"
(ByVal hWnd As Integer, ByVal hAppl As Integer, ByVal hLid As Integer)

Declare Sub DisplayR3SystemInformation Lib "VRFC.DLL"
(ByVal hWnd As Integer, ByVal hAppl As Integer, ByVal hLid As Integer)

Declare Sub DisplayConnectionInformation Lib "VRFC.DLL"
(ByVal hWnd As Integer, ByVal hAppl As Integer, ByVal hLid As Integer)

Sample Code for Calling the API Functions within Visual Basic for Applications

The following code shows sample code for adding a new menu to Excel and code to calling the API functions:

Public hLid As Integer

Public hAppl As Integer

Public hWnd As Integer

Sub auto_open()
Dim hTask As Long
hTask = GetCurrentTask()
hWnd = GetActiveWindow()
Dim a_name As String
a_name = "Excel Demo"
hAppl = RegisterVRFCService(a_name, hTask)
End Sub

Sub auto_close()
UnRegisterVRFCService (hAppl)
End Sub

Sub my_logon()
hLid = RequestVRFCLogon(hWnd, hAppl, 0, "", "", -1, "", "", "", "", "", "", 0, 0)
End Sub

Sub my_logoff()
RequestVRFCLogoff hWnd, hAppl, hLid
End Sub

Sub my_sysinfo()
DisplayR3SystemInformation hWnd, hAppl, hLid
End Sub

Sub my_coninfo()
DisplayConnectionInformation hWnd, hAppl, hLid
End Sub

Sub my_admcon()
hLid = RequestVRFCADMConnections(hWnd, hAppl)
End Sub

Sub my_discon()
RequestVRFCLogoff hWnd, hAppl, 0
End Sub