Skip to Content
0
Former Member
Aug 14, 2009 at 09:39 AM

Current BEx connection

28 Views

Hi!

Sorry for my English (it is translated Google).

Faced with a problem: it is necessary to insert a record field with the name of the record (not his name). Posted a little VBA code to get the last names.

Private Sub FM_ExtGetUserDetail()
On Error GoTo errTrap
Dim objBAPIControl As Object
Dim objUserDetail As Object
Dim address As Object
Dim sapConnection As Object
Dim oWS as WorkSheet

Set objBAPIControl = CreateObject("SAP.Functions")
Set sapConnection = objBAPIControl.Connection

sapConnection.client = "100"
sapConnection.User = login
sapConnection.Language = "RU"
sapC :evil: onnection.ApplicationServer = AS
sapConnection.Password = pass
sapConnection.systemnumber = "0"
sapConnection.System = "00"

If sapConnection.Logon(1, True) <> True Then
MsgBox "No connection to R/3!"
Exit Sub
End If
Set objUserDetail = objBAPIControl.Add("BAPI_USER_GET_DETAIL")

objUserDetail.exports("USERNAME") = sUSER_NAME

returnFunc = objUserDetail.Call

If returnFunc = True Then
Set address = objUserDetail.imports("Address")
Set oWS = ActiveSheet
oWS.Cells(1, 1) = address.Value("DEPARTMENT")
oWS.Cells(1, 2) = address.Value("TEL1_EXT")
oWS.Cells(1, 3) = address.Value("LASTNAME")
oWS.Cells(1, 4) = address.Value("FIRSTNAME")
Else
MsgBox "Error call BAPI_USER_GET_DETAIL ! "
Exit Sub
End If
objBAPIControl.Connection.Logoff

errTrap:
Set address = Nothing
Set objUserDetail = Nothing
Set objBAPIControl = Nothing
Set sapConnection = Nothing

End Sub

But have one problem left:

Now in the code clearly identifies the data to connect to the system. It can be replaced by dialogue to login to the system. But the ideal solution to use the current BEx connection that does not make the user double-enter the registration data.

Q How can this be done?

Try this: Code:

Set sapConnection = Run("BExAnalyzer.xla!sapBEXgetConnection", 0) 

but did not succeed (p_connectionObj = Nothing).

Juggling objects p_connectionObj and g_logonObj result failed.