【问题标题】:Add input box to URL checker macro in excel 2010在 excel 2010 中将输入框添加到 URL 检查器宏
【发布时间】:2016-05-12 03:21:36
【问题描述】:

我在网上找到了以下宏。 我想知道如何添加一个输入框,让我可以告诉宏检查 A 以外的其他列并从 A1 以外的其他单元格开始。

Sub Check_URLs()

    Dim cell As Range
    Dim IE As Object

    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True

    For Each cell In Range("A1", Range("A" & Rows.Count).End(xlUp))

        If Left(cell.Value, 4) = "http" Then

            ' Goto web page
            IE.Navigate cell.Text

            Application.StatusBar = cell.Text & "  is loading. Please wait..."

            ' Wait until web page is loaded
            Do Until IE.ReadyState = 4 'READYSTATE_COMPLETE
            Loop

            Application.StatusBar = ""

            ' Look for text on web page
            If InStr(IE.Document.body.innerText, _
               "HTTP 404") > 0 Then
               cell.Offset(, 1).Value = "zzz"
               Else
               cell.Offset(, 1).Value = "Y"

            End If
        End If
    Next cell

    IE.Quit
    Set IE = Nothing

End Sub

【问题讨论】:

  • 你试过上网吗?就像,谷歌“Inputbox Excel VBA”,我确定你会发现如何 :)

标签: vba excel inputbox


【解决方案1】:

here to learn about the InputBox。然后将该资源添加为书签,因为它包含指向完整 Excel 对象模型(以及其他办公应用程序)的链接,以供将来参考:)

Application.InputBox Method (Excel)

然后您可以从中创建 InputBox 并将其结果分配给 Range 对象:

Dim startRange as Range

Set startRange = Application.InputBox(Prompt:="Select starting cell...", _
                                      Default:="$A$1", _
                                      Type:=8)

然后,转到here 了解如何在给定范围/列/等中找到“最后一行”。

Error in finding last used cell in VBA

最后,相应地调整您的 For each cell... 循环。

或者使用简单的输入框(这很可能需要额外的错误处理,例如,如果有人输入 Steve 怎么办?或者用数字代替字母,等等)

Dim myColumnLetter as String
myColumnLetter = Application.InputBox("Input a column letter.", Default:="A")

' ### Here you may want to validate the input value, 
'     since it could cause errors if it's not a valid input
' ###

For Each cell In Range(myColumnLetter & "1", Range(myColumnLetter & Rows.Count).End(xlUp))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-07
    相关资源
    最近更新 更多