Announcement:
wanna exchange links? contact me at sapchatroom@gmail.com.
Posted by
Admin at
Question from Tom82 on Sep 19 at 5:58 AM Dear all, I am currently trying to write a VBA code in Excel in order to extract financial data from our SAP system to Excel. For this I wrote the below stated code. I would like to use the BAPI GetGLAccountPeriodBalances from the business object GeneralLedger. But I do not know how to fill the cells in Excel with the data. There is always an error when I try to fill the Excel cells with the data from the export parameters (almost at the end of the code). Could anyone of you please tell me how I can extract the period balance from the GL Account to Excel? Thank you in advance! Tom82 Sub RetrieveSAPData() 'Declaration of objects and variables Dim oBAPICtrl As Object Dim oGeneralLedger As Object Dim oCompanyCode As Variant Dim oGLAccount As Variant Dim oFiscalYear As Variant Dim oCurrencyType As Variant Dim oReturn As Object Dim oAccountBalances As Object 'creation of the BAPI ActiveX Control object Set oBAPICtrl = CreateObject("SAP.BAPI.1") 'SAP Logon oBAPICtrl.Connection.Logon If oBAPICtrl.Connection.Logon(1, False) = True Then MsgBox ("SAP Logon erfolgreich") Else: MsgBox ("SAP Logon fehlgeschlagen") End If 'creation of SAP business object GeneralLedger Set oGeneralLedger = oBAPICtrl.GetSAPObject("GeneralLedger") 'declaration of the export parameters Set oReturn = oBAPICtrl.DimAs(oGeneralLedger, "GetGLAccountPeriodBalances", "Return") Set oAccountBalances = oBAPICtrl.DimAs(oGeneralLedger, "GetGLAccountPeriodBalances", "AccountBalances") 'data for the import parameters oCompanyCode = Range("F1") oGLAccount = Range("F2") oFiscalYear = Range("F3") oCurrencyType = Range("F4") 'Calling the BAPI oGeneralLedger.GetGLAccountPeriodBalances CompanyCode:=oCompanyCode, GLacct:=oGLAccount, _ Fiscalyear:=oFiscalYear, CurrencyType:=oCurrencyType, Return:=oReturn, AccountBalances:=oAccountBalances 'write the data from export parameters to the Excel sheet Range("F8").Value = oReturn Range("F9").Value = oAccountBalances 'SAP Logoff oBAPICtrl.Connection.Logoff End Sub | Reply to this email to post your response. __.____._ | _.____.__ |