Application.Run每次迭代

时间:2016-02-23 08:49:32

标签: excel-vba subroutine vba excel

我在一个子过程中出现了一个奇怪的问题,即在一个子过程中添加了新的行(根据用户的选择,可以有1个或更多行)。我想分开AddRowsBelow()子,所以我也可以在其他地方重用它:

Sub macroID()
 On Error Resume Next
 Dim ie As Object
 Set ie = CreateObject("internetexplorer.application")
 Dim doc As HTMLDocument

 Dim valuation As String
 Dim val1 As String, val2 As String

 Set doc = ie.Document
 ie.Visible = True
 ie.navigate "http://www.eppraisal.com/home-values/property/14032-s-atlantic-ave-riverdale-il-60827-59143864/"
 Do
     DoEvents
     Loop Until ie.readyState = READYSTATE_COMPLETE

 Set doc = ie.Document
 valuation = doc.getElementById("eppraisalval")
 Cells(1, 4).Value = valuation
 Application.Wait (Now + TimeValue("0:00:03"))


End Sub

当我将下面的sub作为参数传递时,它会在每次迭代时成功调试row.rr,但是其他代码只在更多行的情况下运行一次 - 其他迭代没有任何反应。它在格式化为Excel表格的范围内运行。

Sub AddRowsBelow(Coord As Range, RowsToAdd As Long, Optional SubName As String)
    Dim i As Integer
    Dim newRowNr As Integer: newRowNr = Coord.Row

    For i = 1 To RowsToAdd
        Coord.Offset(1).EntireRow.Insert xlDown

        If LenB(SubName) <> 0 Then
            newRowNr = newRowNr + 1
            Application.Run SubName, newRowNr
        End If

    Next
End Sub

为什么它不起作用的任何想法?

0 个答案:

没有答案