如何使用 Excel VBA 访问 SAP? [英] How to access SAP using Excel VBA?
问题描述
我正在尝试登录 SAP.Excel VBA 代码为我提供了一个确认我的信息的弹出窗口,但是当我提交表单时,它不会将我带到一个新的 SAP 窗口.
I am trying to log on to SAP. The Excel VBA code gives me a popup window confirming my information however when I submit the form it does not take me to a new SAP window.
另外,有没有办法让所有要求确认我的信息的弹出框自动化?我希望这段代码最终能在一天中的特定时间运行,而我可能无法输入任何数据.
Additionally is there a way to automate all the popup boxes asking for confirmation on my information? 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
推荐答案
既然你想打开一个新的 SAP 窗口",你就必须采取不同的方法!
Since you want to "open a new SAP Window" you have to make a different approach!
首先尝试使用sapshcut"从 DOS 命令行打开 SAP 的新实例:
At First try to open the new instance of SAP from the DOS Commandline with "sapshcut":
C:\Program Files (x86)\SAP\FrontEnd\SAPgui\sapshcut.exe -system="System Test Environment" -client="100" -user="user" -password="password" -language="EN"
如果你的 SystemName 没有空格(我相信是这样!)那么你也可以这样写:
If your SystemName has no Spaces (and I belive so!) then you can write it also like:
C:\Program Files (x86)\SAP\FrontEnd\SAPgui\sapshcut.exe -system=SystemTestEnvironment -client=100 -user=user -password=password -language=EN
当此调用适用于您的凭据时,您可以像这样将其传输到 Excel:
When this call works with your credentials, then you can transfer it to Excel like this:
Sub login1()
Call Shell("C:\Program Files (x86)\SAP\FrontEnd\SAPgui\sapshcut.exe -system=SystemTestEnvironment -client=100 -user=user -password=password -language=EN",vbNormalFocus)
End Sub
您还可以通过在字符串中添加-command=your_tcode"来添加交易.
You could also add a transaction by adding "-command=your_tcode" to the String.
如果您的参数中有空格,并且您只能使用命令行中的 -system="System Test Environment" 启动它,则您必须在 Excel 中使用 -system="""System Test Environment""" 将其转义(!)
If your have spaces in the parameters and you could only start it with -system="System Test Environment" from the Commanline, you will have to escape this in Excel with -system="""System Test Environment""" (!)
这篇关于如何使用 Excel VBA 访问 SAP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!