AS400宏答案不是恒定的

时间:2018-09-26 18:02:23

标签: excel vba excel-vba ibm-midrange

下面是宏,我试图让AS400从excel(列A)中获取数据,然后遍历它并吐出我想要的数据(H列)。问题是只有某些响应出现,而其他响应则没有。我需要帮助,以找到断开连接的位置,某些答案返回而其他答案则为空白。

Sub RMRD()  

   Dim infile As String
   Dim part As String, RipNumber As String
   Dim source As String
   Dim SELECTION As Integer, i As Integer, c As String
   Dim excel As Object
   Dim ACELL As String, HCELL As String
   Dim Verify As Integer
   Dim Result As String

   infile = InputBox$("input FILE NAME INCLUDING PATH?", "FILE   NAME", "C:\CFILES\RMRD.XLSX")
   TDATE = InputBox$("Input Status", "TDATE", "CURRENT")

   i = 2
   Set excel = CreateObject("EXCEL.APPLICATION")
   excel.Visible = True
   excel.Workbooks.Open FileName:=infile
   Verify = MsgBox("IS THIS THE CORRECT SPREADSHEET?", 4, "VERIFY SPREADSHEET")
   If Verify = 7 Then
      excel.Workbooks.Close
      Exit Sub
   End If

   ACELL = "A2"
   HCELL = "H2"

   excel.Range("A1").Select
   excel.activecell.FormulaR1C1 = "RIP NUMBER"

   excel.Range("H1").Select
   excel.activecell.FormulaR1C1 = "PART NUMBER"

   excel.Range(ACELL).Select
   RipNumber = excel.activecell.FormulaR1C1      

   excel.Range(HCELL).Select
   part = excel.activecell.FormulaR1C1

   Do Until Len(Trim(RipNumber)) = 0   
      With Session
         .TransmitTerminalKey rcIBMClearKey
         .WaitForEvent rcKbdEnabled, "30", "0", 1, 1
         .WaitForEvent rcEnterPos, "30", "0", 1, 1
         .TransmitANSI "RMRD"
         .TransmitTerminalKey rcIBMEnterKey
         .WaitForEvent rcKbdEnabled, "30", "0", 1, 1
      '.WaitForEvent rcEnterPos, "30", "0", 2, 6
         .WaitForDisplayString "FN:", "30", 2, 2
         .MoveCursor 5, 12
         .TransmitANSI RipNumber
         .TransmitTerminalKey rcIBMEnterKey
         .WaitForEvent rcKbdEnabled, "30", "0", 1, 1
         Result = .GetDisplayText(4, 11, 20)

         excel.Range(HCELL).Select
         excel.activecell.FormulaR1C1 = Result       

         i = i + 1
         c = Trim$(Str$(i))
         ACELL = "A" + c
         HCELL = "H" + c

         excel.Range(ACELL).Select
         RipNumber = excel.activecell.FormulaR1C1

         excel.Range(HCELL).Select
         part = excel.activecell.FormulaR1C1
      End With
   Loop
End Sub

结果在下面-仅运行的某些Rip产生了零件编号。所有这些RIP都有与之关联的部件号,这是令人困惑的部分。

RIP NUMBER零件编号

0011830753
0011651498
0011663984
0011673690
0011779594
0011679940
0011608375
0011608375
0011608375
0011612829
0011612829 K37-1010-100111120
0011612829
0011613986
0011613986
0011613986
0011613986
0011613987
0011623625
0011627268
0011630146
0011646287
0011646287
0011646287
0011646455
0011653346
0011656828
0011656828
0011647748
0011662058
0011662058
0011665727
0011674436
0011693803
0011693803
0011656828
0011656828 K37-1010-100111120
0011662058
0011662058
0011693803
0011693803
0011693803
0011701262
0011701262
0011701262
0011701262
0011703587
0011709655
0011713364
0011713364
0011713364
0011732765
0011732765
0011732765
0011734094
0011734094 K37-1010-100111120
0011734094
0011738281
0011738281
0011738281

0 个答案:

没有答案