【问题标题】:how to get msg box with two conditions in excel macro?如何在excel宏中获取具有两个条件的消息框?
【发布时间】:2015-09-24 11:23:01
【问题描述】:

//大家好,如果你为我做这件事,你会和我约会。 我正在使用以下宏打开“J:J”列中的超链接。并添加了一个 MsgBox 来循环它。如果用户点击它,我将继续下一步。 我需要 MsgBox 上的“是”和“否”按钮。如果我点击 Yes 我应该继续,如果我点击 No 然后我想调用另一个模块,比如 Sub refresh() 。提前致谢。

Sub OpenLinks()
    Dim Cell As Range
    Set LinkRng = Range("J1").CurrentRegion.Columns(1)
    On Error Resume Next
    For Each Cell In LinkRng.Cells
        Cell.Hyperlinks(1).Follow
        Do
        If ie.readyState = 4 Then
            ie.Visible = False
            Exit Do
        Else
            DoEvents
        End If
    Loop
    MsgBox "OK"
    ie.Visible = True
    Next
    On Error GoTo 0
End Sub

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    像这样?

    Sub OpenLinks()
        Dim LinkRng As Range
        Set LinkRng = Range("J1").CurrentRegion.Columns(1)
        For Each cell In LinkRng.Cells
            If MsgBox("Continue?", vbYesNo) = vbYes Then
                Cell.Hyperlinks(1).Follow
            Else
                Refresh
            End If
            Do
            If ie.readyState = 4 Then
                ie.Visible = False
                Exit Do
            Else
                DoEvents
            End If
        Loop
        MsgBox "OK"
        ie.Visible = True
        Next
        On Error GoTo 0
    End Sub
    

    【讨论】:

    • If i click on Yes i should continue and if i click on No then I want to called another module something like Sub refresh() 你能提供一个完整的规范吗?
    • 如果我按下“是”按钮,那么我想继续打开网址。如果我按“否”,那么我应该调用另一个模块。
    • 是的...我也想继续处理其他单元格.. :) 我想从下一个单元格继续。
    • 修改后一切正常。非常感谢@Macro Man :)
    猜你喜欢
    • 2021-09-24
    • 1970-01-01
    • 2017-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多