VBA Excel-SAP connector

Cime14

New Member
Joined
Dec 19, 2017
Messages
30
Hi guys,

i would need help with few things :)
1. Is it possible to extract excel format from SAP reather than file format?
2. Is it possible to use vba code for copying data from excel to SAP? Can you proivide sample of the code (from column A, rows 1-10 for example) to SAP transaction code FBL1N?
3. Can you help me merge below two VBA codes....aparently I am doing something wrong :(
Thank you in advance!!


PART1:
Sub SAP_Open()

Dim SapGui
Dim Applic
Dim connection
Dim session
Dim WSHShell
Shell "C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe", vbNormalFocus
Set WSHShell = CreateObject("WScript.Shell")
Do Until WSHShell.AppActivate("SAP Logon ")
Application.Wait Now + TimeValue("0:00:01")
Loop
Set WSHShell = Nothing
Set SapGui = GetObject("SAPGUI")
Set Applic = SapGui.GetScriptingEngine
On Error Resume Next
Set connection = Applic.OpenConnection("SG00 - P34: SHAPE Production ERP (with SSO)", True)
Set connection = Applic.OpenConnection("SP01 - P34 : SHAPE ERP Production (with SSO)", True)


End Sub

PART2:
Sub test_transaction()
Dim App, connection, session As Object
Set SapGuiAuto = GetObject("SAPGUI")
Set App = SapGuiAuto.GetScriptingEngine
Set connection = App.Children(0)
Set session = connection.Children(0)

session.findById("wnd[0]/tbar[0]/okcd").Text = "FBL1N" 'change tranasaction
session.findById("wnd[0]/tbar[0]/btn[0]").press
session.findById("wnd[0]/tbar[1]/btn[17]").press
session.findById("wnd[1]/usr/txtV-LOW").Text = "USER1" 'change variant name
session.findById("wnd[1]/usr/txtENAME-LOW").Text = "USER1" ' change variant creator
session.findById("wnd[1]/tbar[0]/btn[8]").press
session.findById("wnd[0]/tbar[1]/btn[8]").press 'start process

'save as local file - spreadsheet

session.findById("wnd[0]/mbar/menu[0]/menu[3]/menu[2]").Select
session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[1,0]").Select
session.findById("wnd[1]/tbar[0]/btn[0]").press

session.findById("wnd[1]/usr/ctxtDY_PATH").Text = "C:\Users\..." 'filepath for export

session.findById("wnd[1]/usr/ctxtDY_FILENAME").Text = "TEST" 'filename
session.findById("wnd[1]/tbar[0]/btn[11]").press

End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top