|
楼主 |
发表于 2020-6-23 11:39
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
看到这么多大佬关注,还是很感动。花了两周时间学习了一下Python和Selenium,后来发现公司电脑不让安装Python(需要全球Tech Director approve);只好退而求其次研究了一下DOM和老掉牙的对IE编程。基本解决了我的所有诉求,废话少说,直接上代码。- '---------------Fill Page 2---------------------------------------------------
- Sub fill_GBTRS_P2()
- Dim Cols(8) As Integer, i%, j%, RowLen%, ColsLen%, BORows%, BOCols%
- Dim ObjChkbtn As Object, d As Object
- Dim mShellwindows As New ShellWindows
- Dim objIE As InternetExplorer
- Dim objFrame As FramesCollection
- Dim objDOC As HTMLDocument
- Dim Gbtrs_frm As Object, MyTable As Object, MySelect As Object
- Dim TestArr
- Dim isSelect As Boolean, IEOpen As Boolean
- Dim Address As String, rng1 As Range
- Dim BOSum As Double
-
- Address = Selection.Address
- isSelect = False
- Erase Cols
- i = 4
- Application.ScreenUpdating = False
-
- '=======================connect with the opened GBTRS page===================================================
- IEOpen = False
- For Each objIE In mShellwindows
- If objIE.LocationURL = "http://pap/" Then
- IEOpen = True
- Exit For
- End If
- Next
- If Not IEOpen Then
- MsgBox "Please Use Internet Explorer to open the PAP system. " & Chr(10) & Chr(10) & _
- "This tool only support IE, use IE to open the work order Page 1! ", vbCritical, "Open IE First, Exit now"
- Exit Sub
- End If
- While objIE.Busy = True Or objIE.readyState <> 4
- DoEvents
- Wend
- Set objFrame = objIE.document.frames
- Set objDOC = objFrame("LZMain").document
- Set Gbtrs_frm = objDOC.frames("BrowseArea").document
-
- '===================------------------------------select group tests by checkbox-----------------------------------============================
- With ActiveSheet
- For Each ObjChkbtn In .OLEObjects 'shapes("group").groupitems
- If TypeName(ObjChkbtn.Object) = "CheckBox" Then
- If ObjChkbtn.Object.Value = True Then
- Cols(i) = CInt(Right(ObjChkbtn.Name, 1)) + 3
- isSelect = True
- End If
- i = i + 1
- End If
- Next ObjChkbtn
- End With
- If Not isSelect Then Cols(4) = 4
-
- TestArr = ThisWorkbook.Worksheets("Sheet1").ListObjects("Tests").Range
- Set d = CreateObject("scripting.Dictionary")
-
- For i = 2 To UBound(TestArr)
- isSelect = False
- For j = 4 To UBound(Cols)
- If Cols(j) > 1 Then
- If TestArr(i, Cols(j)) * 1 = 1 Then
- isSelect = True
- Exit For
- End If
- End If
- Next j
- If isSelect Then d(TestArr(i, 1)) = TestArr(i, 2) & StrLink & TestArr(i, 3) '---------put selected tests into dictionary
- Next i
- Erase TestArr
- TestArr = d.keys
-
-
- If ThisWorkbook.ActiveSheet.Cells(100, 100) <> RRFlag And Len(Cells(100, 100)) = 0 Then '====Locate Base Oil Table===========
- '--------------------计算基础油行数,配方列,添加剂首行等参数
- Application.ScreenUpdating = True '===================select data area=====================================
- On Error Resume Next
- Set rng1 = Application.InputBox("Please select ALL Base Oils in Column A", "Select All Base Oils", Address, , , , , Type:=8)
- ' Set rng2 = Application.InputBox("Please select torque reduction data columns at the same row as before", "Select results", Address, , , , , Type:=8)
- On Error GoTo 0
-
- If Not rng1 Is Nothing Then
- BORows = rng1.Rows.Count
- BOCols = 2
- Do While WorksheetFunction.CountA(ActiveSheet.ListObjects("myFormulation").DataBodyRange.Columns(BOCols + 1)) > 2
- BOCols = BOCols + 1
- Loop
- Set MyTable = Gbtrs_frm.getElementById("newblendstable")
- RowLen = MyTable.Rows.Length
- ColsLen = MyTable.Rows(0).Cells.Length
- If BOCols > ColsLen - 5 Then BOCols = ColsLen - 4
- Set rng1 = rng1.Resize(, BOCols)
- Do While RowLen - 3 < BORows
- MyTable.Rows(RowLen - 2).Cells(0).Children(0).Click
- myDelay 0.2
- RowLen = RowLen + 2
- Loop
- For j = 1 To BOCols
- If j > 1 Then BOSum = WorksheetFunction.Sum(rng1.Columns(j))
- For i = 1 To BORows '====================================fill baseoil part 基础油部分=======================================
- If Len(rng1(i, j)) > 0 Then
- If j = 1 Or BOSum = 100 Then
- MyTable.Rows(i).Cells(j).Children(0).Value = rng1(i, j)
- Else
- MyTable.Rows(i).Cells(j).Children(0).Value = Format(100 * rng1(i, j) / BOSum, "0.00")
- End If
- End If
- Next i
- Next j
- Set MyTable = Nothing
- End If
-
- Set rng1 = Nothing
- On Error Resume Next
- Do
- Set rng1 = Application.InputBox("Please select ALL Components in Column A", "Select All Components", Address, , , , , Type:=8)
- DoEvents
- Loop Until Not rng1 Is Nothing
- On Error GoTo 0
- Application.ScreenUpdating = False
-
- BORows = rng1.Rows.Count
- BOCols = 2
- Do While WorksheetFunction.CountA(ActiveSheet.ListObjects("myFormulation").DataBodyRange.Columns(BOCols + 1)) > 2
- BOCols = BOCols + 1
- Loop
- Set MyTable = Gbtrs_frm.getElementById("newcompstable") 'getElementsByTagName("table")(1) 单剂部分
- RowLen = MyTable.Rows.Length
- ColsLen = MyTable.Rows(1).Cells.Length
- If BOCols > ColsLen - 4 Then BOCols = ColsLen - 3
- Set rng1 = rng1.Resize(, BOCols)
- If BORows > RowLen - 4 Then Gbtrs_frm.parentWindow.execScript "morelines('newcompstable','comp'," & RowLen - 3 & "," & BORows - RowLen + 4 & ")", "JScript"
- myDelay 0.3
- For i = 1 To BORows '====================================fill ocmponents part=======================================
- For j = 1 To BOCols
- If Len(rng1(i, j)) > 0 Then MyTable.Rows(i).Cells(j).Children(0).Value = rng1(i, j)
- Next j
- Next i
- Set MyTable = Nothing
- Set rng1 = Nothing
- End If
-
- Set MyTable = Gbtrs_frm.getElementById("nonshivatable") '====------------------Locate test items Table 测试部分----------------===========
- RowLen = MyTable.Rows.Length
- ColsLen = MyTable.Rows(1).Cells.Length
- BORows = d.Count
- If BORows > RowLen - 4 Then Gbtrs_frm.parentWindow.execScript "morelines('nonshivatable','nonperf'," & RowLen - 3 & "," & BORows - RowLen + 6 & ")", "JScript"
- myDelay 0.3
-
- For i = 1 To BORows
- Set MySelect = MyTable.Rows(i).Cells(0).Children(4)
- ' MySelect.selectedIndex = 5
- MySelect.Value = "TPV00000R=10"
- MySelect.FireEvent "onchange"
- myDelay 0.1
-
- With MyTable.Rows(i).Cells(0)
- .Children(0).Value = TestArr(i - 1)
- .Children(2).Value = Split(d(TestArr(i - 1)), StrLink)(0)
- .Children(3).Value = Split(d(TestArr(i - 1)), StrLink)(1)
- End With
-
- Next i
- Application.ScreenUpdating = True
- MsgBox "Successfully fill all the data into the system", vbOKOnly
- Set MyTable = Nothing
- Set rng1 = Nothing
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|