Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

vba - Pulling data from SAP using Excel Macros

So I am trying to pull data from SAP using excel macros. I am new to VBA so please bear with me. I found a topic on here called VBA pulling data from SAP for dummies and I am confused. What I am trying to do is as follows:

  1. Copy a notification number from a list in excel.
  2. Go to the appropriate screen in SAP and paste this number in the search box.
  3. Open the long text box.
  4. Copy the long text.
  5. Paste into excel.

Here is the link VBA pulling data from SAP for dummies

I can't seem to get by Set session = connection.Children(0) 'Get the first session (window) on that connection.

Any help is much appreciated. The reason I am doing this is because SAP wont export longtext and it takes an act of God to get it fixed.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is what i use for all my connections for SAP:

'Connect to SAP to run automation.
        If Not IsObject(SAP_applic) Then
            Set SapGuiAuto = GetObject("SAPGUI")
            Set SAP_applic = SapGuiAuto.GetScriptingEngine
        End If
            Set connection = SAP_applic.Children(0)
        If Not IsObject(connection) Then
            Set connection = application.Children(0)
        End If
        If Not IsObject(session) Then
            Set session = connection.Children(0)
        End If
        If IsObject(WScript) Then
            WScript.ConnectObject session, "on"
            WScript.ConnectObject application, "on"
        End If

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...