我有一个连接到SAP并提取数据的宏,我有一个自动化宏的任务,以便可以在计划的时间内提取数据。但是问题是我在运行时得到了弹出窗口我需要单击“确定”按钮将其连接到SAP的宏。
我有一个密码
If obj_SAP_Connection.Logon(0, False) <> True Then
我将其更改为
If obj_SAP_Connection.Logon(0, True) <> True Then
绕过弹出窗口,但显示与RFC初始化有关的错误消息
我在下面粘贴了完整的宏代码以供参考,请帮助我解决问题
Function Connect_to_SAP() As Integer
出错时转到ERR_CTS int_ERROR_CODE_CURR = 107
If obj_SAP_Connection.IsConnected <> 1 Then
'XXXXXXX
' obj_SAP_Connection.Client = "600"
' obj_SAP_Connection.ApplicationServer = "warusap001.diageo.net"
' obj_SAP_Connection.System = "DEP"
'' obj_SAP_Connection.SystemNumber = "01"
' obj_SAP_Connection.User = "DOBOIS"
' obj_SAP_Connection.Language = "EN"
' obj_SAP_Connection.autologon = 1
' obj_SAP_Connection.SNC = True
' obj_SAP_Connection.SNCName = "p:DoboIstv@GUWW.NET"
'' 'obj_SAP_Connection.SNCName = "p:sapDEP/warusap001.diageo.net@GUWW.NET"
' obj_SAP_Connection.SNCQuality = 3
'XXXXXXX
obj_SAP_Connection.Autologon = 0
'Try to log on to SAP
If obj_SAP_Connection.Logon(0, False) <> True Then
'str_System = obj_SAP_Connection.System
int_ERROR_CODE_CURR = 109
GoTo ERR_CTS
End If
str_System = obj_SAP_Connection.System
End If
'obj_SAP_Connection.Logoff
Connect_to_SAP = 0
On Error GoTo 0
Exit Function
ERR_CTS:
ADD_VBA_Error "SAP_NEW", "Connect_to_SAP"
Add_item_LOG Convert_Err_Code_to_Msg(int_ERROR_CODE_CURR), CStr("Error code : " & int_ERROR_CODE_CURR), _
"", "", "", "", False, "E"
Connect_to_SAP = int_ERROR_CODE_CURR
End Function
Sub SAP_Initialize_Objects()
Set obj_BAPI_Control = CreateObject("SAP.Functions")
Set obj_SAP_Connection = obj_BAPI_Control.Connection
bln_SAP_Objects_Initiated = True
End Sub
Function SAP_Initialize_RFC_RT()
'_SIRR
On Error GoTo ERR_SIRR
int_ERROR_CODE_CURR = 102
If bln_SAP_Object_RFC_RT_Initiated = False Then
'Function Module
Set obj_SAP_FM = obj_BAPI_Control.Add("RFC_READ_TABLE")
'IMPORTS
Set obj_SAP_RT_IMP_QUERY_TABLE = obj_SAP_FM.Exports("QUERY_TABLE")
Set obj_SAP_RT_IMP_DELIMITER_OPT = obj_SAP_FM.Exports("DELIMITER")
Set obj_SAP_RT_IMP_NO_DATA_OPT = obj_SAP_FM.Exports("NO_DATA")
Set obj_SAP_RT_IMP_ROWSKIPS_OPT = obj_SAP_FM.Exports("ROWSKIPS")
Set obj_SAP_RT_IMP_ROWCOUNT_OPT = obj_SAP_FM.Exports("ROWCOUNT")
'TABLES
Set obj_SAP_RT_TBL_DATA = obj_SAP_FM.Tables("DATA")
Set obj_SAP_RT_TBL_FIELDS = obj_SAP_FM.Tables("FIELDS")
Set obj_SAP_RT_TBL_OPTIONS = obj_SAP_FM.Tables("OPTIONS")
bln_SAP_Object_RFC_RT_Initiated = True
End If
SAP_Initialize_RFC_RT = 0
On Error GoTo 0
Exit Function
ERR_SIRR:
ADD_VBA_Error "SAP_NEW", "SAP_Initialize_RFC_RT"
Add_item_LOG Convert_Err_Code_to_Msg(int_ERROR_CODE_CURR), CStr("Error code : " & int_ERROR_CODE_CURR), _
"", "", "", "", False, "E"
SAP_Initialize_RFC_RT = int_ERROR_CODE_CURR
End Function
Function SAP_Close_RFC_RT()
'_SCRR
On Error GoTo ERR_SCRR
int_ERROR_CODE_CURR = 103
If bln_SAP_Object_RFC_RT_Initiated = True Then
'IMPORTS
Set obj_SAP_RT_IMP_QUERY_TABLE = Nothing
Set obj_SAP_RT_IMP_DELIMITER_OPT = Nothing
Set obj_SAP_RT_IMP_NO_DATA_OPT = Nothing
Set obj_SAP_RT_IMP_ROWSKIPS_OPT = Nothing
Set obj_SAP_RT_IMP_ROWCOUNT_OPT = Nothing
'TABLES
Set obj_SAP_RT_TBL_DATA = Nothing
Set obj_SAP_RT_TBL_FIELDS = Nothing
Set obj_SAP_RT_TBL_OPTIONS = Nothing
'Function Module
Set obj_SAP_FM = Nothing
bln_SAP_Object_RFC_RT_Initiated = False
End If
SAP_Close_RFC_RT = 0
On Error GoTo 0
Exit Function
ERR_SCRR:
ADD_VBA_Error "SAP_NEW", "SAP_Close_RFC_RT"
Add_item_LOG Convert_Err_Code_to_Msg(int_ERROR_CODE_CURR), CStr("Error code : " & int_ERROR_CODE_CURR), _
"", "", "", "", False, "E"
SAP_Close_RFC_RT = int_ERROR_CODE_CURR
End Function