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

时间:2019-05-15 11:51:16

标签: excel vba sap

首先,我能够将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上开始提取。

1 个答案:

答案 0 :(得分:0)

像这样,您还应该缩进代码:

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