callfromexcel

来源:互联网 发布:倒计时js代码 编辑:程序博客网 时间:2024/05/22 16:39
Dim R3, App As ObjectDim Customers, Customer As ObjectDim Result As Boolean'**********************************************'Create Server object and Setup the connection'**********************************************Sub SAP_Logon()Set R3 = CreateObject("RFC.ServerObject")Set App = R3.ApplicationR3.connection.client = "010"'R3.connection.user = "SAP*"'R3.connection.password = "19920706"R3.connection.user = "CPICUSER"R3.connection.password = "19920706"R3.connection.language = "E"R3.connection.Gatewayhost = ""R3.connection.Gatewayservice = ""R3.connection.hostname = "SAPENT"R3.connection.destination = "E40"R3.connection.system = "00"If R3.connection.logon <> True Then   App.Quit   Exit SubEnd IfEnd SubSub Command1_Click()SAP_LogonGet_MaraSAP_LOGOFFEnd SubSub SAP_LOGOFF()R3.Close False            'do not save the server objectApp.QuitEnd SubSub Get_cust()Result = R3.RFC_CUSTOMER_GET(Exception, KUNNR:="*", CUSTOMER_T:=Customers)If Result <> True Then  MsgBox (Exception)  App.Quit  Exit SubEnd If'**************************************'Display table header'**************************************Cells(3, 1) = "Customer ID"Cells(3, 2) = "Customer Name"Cells(3, 3) = "Zip Code"Range(Cells(3, 1), Cells(3, 3)).Font.Bold = True'**************************************'Display Contents of the customer table''If many customers are expected, use'the second alternative'**************************************bManyCustomers = FalseIf (bManyCustomers = False) Then  i = 4  For Each Customer In Customers.Rows     Cells(i, 1) = Customer("KUNNR")     Cells(i, 2) = Customer("NAME1")     Cells(i, 3) = Customer("PSTLZ")     i = i + 1  NextElse  For i = 1 To Customers.RowCount     Cells(i, 1) = Customers(i, "KUNNR")     Cells(i, 2) = Customers(i, "NAME1")     Cells(i, 3) = Customers(i, "PSTLZ")  NextEnd IfEnd SubSub Get_Mara()Dim Materials, Material As ObjectResult = R3.Y_RFC_MARA_GET(Exception, MATNR:="S0039*", BWKEY:="1331", BWART:="", T_MARA:=Materials)If Result <> True Then  MsgBox (Exception)  App.Quit  Exit SubEnd If'**************************************'Display table header'**************************************Cells(3, 1) = "Material No"Cells(3, 2) = "Material Name"Cells(3, 3) = "Zip Code"Range(Cells(3, 1), Cells(3, 3)).Font.Bold = True'**************************************'Display Contents of the customer table''If many customers are expected, use'the second alternative'**************************************bManyCustomers = FalseIf (bManyCustomers = False) Then  i = 4  For Each Material In Materials.Rows     Cells(i, 1) = Material("MATNR")     Cells(i, 2) = Material("MAKTX")     Cells(i, 3) = Material("VERPR")     i = i + 1  NextElse  For i = 1 To Materials.RowCount     Cells(i, 1) = Materials(i, "MATNR")     Cells(i, 2) = Materials(i, "MAKTX")     Cells(i, 3) = Materials(i, "VERPR")  NextEnd IfEnd Sub
原创粉丝点击