如何使用 SAP 和 vba 改变数据?

How to vary data using SAP and vba?

首先,我能够将 SAP GUI 连接到 vba。我设法获得了一个有效的脚本,它向我发送了一个自动交易。我想知道如何在 SAP 上输入数据,例如日期是可变的,因为我必须每年更改日期?

   If Not IsObject(application) Then
   Set SapGuiAuto  = GetObject("SAPGUI")
   Set application = SapGuiAuto.GetScriptingEngine
   End If
   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 
   session.findById("wnd[0]/usr/tabsTABSTRIP_TABBL1/
 tabpUCOM1/ssub%_SUBSCREEN_TABBL1:RFBILA00:0001/txtBILBJAHR").text = "2015"

例如,我希望“2015”日期可变,我希望每个月都可以更改此日期以放置另一个日期,而无需再次在 SAP GUI 上开始提取。

像这样,你也应该缩进你的代码:

Option Explicit
Sub Test()

    Dim MyYear As String

    MyYear = Format(Date, "yyyy")
    If Not IsObject(Application) Then
        Set SapGuiAuto = GetObject("SAPGUI")
        Set Application = SapGuiAuto.GetScriptingEngine
    End If

    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

    Session.findById("wnd[0]/usr/tabsTABSTRIP_TABBL1/tabpUCOM1/ssub%_SUBSCREEN_TABBL1:RFBILA00:0001/txtBILBJAHR").Text = MyYear

End Sub