我有下面的VBA代码,它允许我从文件中的Excel行填充Internet Explorer上Intranet站点中的字段,但现在我想知道是否有一种方法可以循环到最后一行非空,而无需手动重复这些行,以下是代码:
`Sub template()
Application.DisplayAlerts = False
Application.WindowState = xlMinimized
On Error Resume Next
Dim objApp
Dim objIE
Dim objWindow
Dim ie As Object
Dim strURL
Set ie = CreateObject("InternetExplorer.Application")
Set objApp = CreateObject("Shell.Application")
Set objIE = Nothing
strURL = "http://Intranet"
For Each objWindow In objApp.Windows
If (InStr(objWindow.Name, "Internet Explorer")) Then
If (objWindow.LocationURL = strURL) Then
Set objIE = objWindow
Exit For
End If
End If
Next
If (objIE Is Nothing) Then
Set objIE = CreateObject("InternetExplorer.Application")
objIE.navigate (strURL)
End If
With objIE
.Visible = True
Do While .Busy Or .readyState <> 4
Loop
Do While .document.readyState <> "complete"
Loop
**the first line:**
.document.getelementbyID("inputND").Value = Worksheets("Feuil1").Range("A2")
.document.getelementbyID("inputND").innerText = Worksheets("Feuil1").Range("A2")
.document.getElementsByTagName("button")(1).Click
Application.Wait Now + TimeValue("00:00:01")
.document.getelementbyID("categorisation_1").Value = Worksheets("Feuil1").Range("B2") & ": Object" '.Value = ": Object"
Application.Wait Now + TimeValue("00:00:01")
.document.getelementbyID("categorisation_2").Value = Worksheets("Feuil1").Range("D2") & ": Object"
Application.Wait Now + TimeValue("00:00:01")
.document.getelementbyID("categorisation_3").Value = Worksheets("Feuil1").Range("F2") & ": Object"
Application.Wait Now + TimeValue("00:00:01")
MsgBox "Please check before continuing", vbMsgBoxSetForeground + vbSystemModal
**the second line:**
.document.getelementbyID("link61").Click
.navigate "http://Intranet"
Application.Wait Now + TimeValue("00:00:01")
.document.getelementbyID("inputND").Value = Worksheets("Feuil1").Range("A3")
.document.getelementbyID("inputND").innerText = Worksheets("Feuil1").Range("A3")
.document.getElementsByTagName("button")(1).Click
Application.Wait Now + TimeValue("00:00:01")
.document.getelementbyID("categorisation_1").Value = Worksheets("Feuil1").Range("B3") & ": Object" '.Value = ": Object"
Application.Wait Now + TimeValue("00:00:01")
.document.getelementbyID("categorisation_2").Value = Worksheets("Feuil1").Range("D3") & ": Object"
Application.Wait Now + TimeValue("00:00:01")
.document.getelementbyID("categorisation_3").Value = Worksheets("Feuil1").Range("F3") & ": Object"
Application.Wait Now + TimeValue("00:00:01")
MsgBox "Please check before continuing", vbMsgBoxSetForeground + vbSystemModal
.document.getelementbyID("link61").Click
**the third line:**
'........................
End With
Application.DisplayAlerts = True
End Sub`
第一行:Worksheets("Feuil1").Range("A2");Worksheets("Feuil1").Range("B2");Worksheets("Feuil1").Range("D2");Worksheets("Feuil1").Range("F2")
第二行:Worksheets("Feuil1").Range("A3");Worksheets("Feuil1").Range("B3");Worksheets("Feuil1").Range("D3");Worksheets("Feuil1").Range("F3")
第三行:Worksheets("Feuil1").Range("A4");Worksheets("Feuil1").Range("B4");Worksheets("Feuil1").Range("D4");Worksheets("Feuil1").Range("F4")
依此类推,直到最后一个非空行。
我不希望代码的以下部分每次在MsgBox之后重复,我希望代码进入sheet1的第二行,以此类推,直到最后一个非空行
.document.getelementbyID("inputND").Value = Worksheets("Feuil1").Range("A2")
.document.getelementbyID("inputND").innerText = Worksheets("Feuil1").Range("A2")
.document.getElementsByTagName("button")(1).Click
Application.Wait Now + TimeValue("00:00:01")
.document.getelementbyID("categorisation_1").Value = Worksheets("Feuil1").Range("B2") & ": Object" '.Value = ": Object"
Application.Wait Now + TimeValue("00:00:01")
.document.getelementbyID("categorisation_2").Value = Worksheets("Feuil1").Range("D2") & ": Object"
Application.Wait Now + TimeValue("00:00:01")
.document.getelementbyID("categorisation_3").Value = Worksheets("Feuil1").Range("F2") & ": Object"
Application.Wait Now + TimeValue("00:00:01")
MsgBox "Please check before continuing", vbMsgBoxSetForeground + vbSystemModal
我希望现在能说得更清楚,但如果你有任何问题,请问月份,谢谢
2条答案
按热度按时间sshcrbum1#
您只会得到最后一个填充行:
并且,根据您要关注的列,您可以放置适当的索引:1 - A、2 - B等,作为
Cells
中的第二个参数vxf3dgd42#
我在checkbox方法上做了一些改进,所以我做了如下操作:
检查的第一行工作得很好,但第二行不行,在执行宏后,我用黄色突出显示了以下代码行: