cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Scripting - using with Excel

09-15-2021 3:00 PM
1347 views 1 comments
0 Likes
SAP Managed Tags
Subscribe

I created a short script in SAP by recording my steps, to generate the report for one material number, but I pasted this material from my hand - line 24. I would like to use excel in the future for it. I mean I would like the data to be copied from a specific Excel cell to SAP.

I am not sure how to connect SAP with Excel, or how to retrieve data from specific cells. If you have any example of code it would be nice if you share it with me

0 Likes

Accepted Solutions (0)

Answers (1)

Answers (1)

0 Likes

Hi,

The code should be as follows:

Sub code()

Dim sap As Object

Dim conn As Object

Set sap = CreateObject("SAP.Functions")

Set conn = sap.Connection

Set SapGuiAuto = GetObject("SAPGUI")

Set SAPApp = SapGuiAuto.GetScriptingEngine

Set SAPCon = SAPApp.Children(0)

Set session = SAPCon.Children(0)

Set Macro1 = Workbooks("Configuration.xlsb")

Application.ScreenUpdating = False

Macro1.Activate

Sheets("Class").Select

On Error Resume Next

I = 2

Do While ActiveSheet.Range("a" & I) <> ""

Application.DisplayAlerts = False

-->your SAP script goes over here. you need to refer a cell instead of single material number in the code.

Application.DisplayAlerts = True

I = I + 1

Macro1.Activate

Sheets("Class").Select

Application.ScreenUpdating = True

'DoEvents

Loop

End Sub