Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

excel - 使用Excel宏访问树液时遇到麻烦(trouble using excel macro for access to sap)

I am trying to make a macro in excel that will log me on to SAP, the code I have gives me a popup window confirming my information however when I submit the form it does not take me to a new SAP window.

(我正在尝试在excel中创建一个宏,该宏将使我登录到SAP,我得到的代码为我提供了一个弹出窗口,用于确认我的信息,但是,当我提交表单时,它不会带我到新的SAP窗口。)

Is there extra code I am missing or did i type something wrong?

(我是否缺少其他代码,或者输入的内容有误?)

Additionally is there a way to automate all the popup boxes asking for confirmation on my information, as I want this code eventually to run at certain times of the day, and I might not be available to input any data.

(此外,还有一种方法可以使所有弹出框自动化,以要求对我的信息进行确认,因为我希望此代码最终在一天的某些时间运行,并且可能无法输入任何数据。)

Sub login1()
Dim sap As Object
Dim conn As Object

Set sap = CreateObject("SAP.Functions")
Set conn = sap.Connection
conn.System = "System Test Environment"
conn.client = "100"
conn.user = "user"
conn.Password = "password"
conn.Language = "EN"

If conn.logon(0, False) <> True Then
    MsgBox "Logon to the SAP system is not possible", vbOKOnly, "Comment"
    Else

End If
End Sub
  ask by user3456612 translate from so

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

1 Reply

0 votes
by (71.8m points)

This Macro will never open a SAP Window - it will create an SAP-Object within VBA where you can work with SAP-RFC-Functions.

(该宏永远不会打开SAP窗口-它将在VBA中创建一个SAP对象,您可以在其中使用SAP-RFC-Functions。)

(Reading Data from SAP, Writing Data into SAP)

((从SAP读取数据,将数据写入SAP))

In your version the SAP connection will be unaccessible after "End Sub".

(在您的版本中,在“ End Sub”之后将无法访问SAP连接。)

You have to declair the Object outside the sub.

(您必须在子对象外部对对象进行装饰。)

This works silent (without dialog) for me:

(这对我来说是静音的(无对话框):)

Dim sap As Object

Public Function login1() As Boolean

  Set sap = CreateObject("SAP.Functions")

  sap.Connection.System = "System Test Environment"
  sap.Connection.client = "100"
  sap.Connection.user = "user"
  sap.Connection.Password = "password"
  sap.Connection.Language = "EN"

  If sap.Connection.logon(0, False) <> True Then
    sap.RemoveAll
    MsgBox "Logon to the SAP system is not possible", vbOKOnly, "Comment"
  Else
    login1 = true
  End If

End Function

Public Function SAPLogoff()
    On Error Resume Next
    sap.RemoveAll
    sap.Connection.logoff

    LoggedOn = False
    Set sap = Nothing
    'Set conn = Nothing
End Function

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...