vba - 在继续循环之前提示用户

标签 vba excel

我正在创建一个 VB 宏来循环遍历单元格并将值复制并粘贴到记事本中。我想做的是提示用户并询问他们是否愿意在进行下一次迭代之前继续。

Sub LoopTest()

Dim rng As Range, cell As Range
Set rng = Range("A1:A2")
For Each cell In rng

cell.Copy

'Worksheets("Sheet1").Range("A" + j).Copy
Shell "C:\Windows\system32\notepad.exe", vbNormalFocus
SendKeys "^V"
DoEvents
SendKeys "{ENTER}", True
Next cell


End Sub

最佳答案

尝试这个:

Sub LoopTest()

    Dim rng As Range, cell As Range
    Set rng = Range("A1:A2")
    For Each cell In rng

        cell.Copy

        'Worksheets("Sheet1").Range("A" + j).Copy
        Shell "C:\Windows\system32\notepad.exe", vbNormalFocus
        SendKeys "^V"
        DoEvents
        SendKeys "{ENTER}", True

        If MsgBox("Continue?", vbYesNo, "Confirm") = vbNo Then

            Exit For

        End If

    Next cell


End Sub

关于vba - 在继续循环之前提示用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33663275/

相关文章:

vba - 使用 (i,j) 格式对范围进行平均

vba - Month() 函数没有返回正确的值

excel - 在单元格中复制公式

vba - GetObject ("SAPGUI"返回什么类型的对象)?

excel - 检查 Outlook 中是否存在附件并显示数据

vba - 如何在 VBA 中隐藏多组列?

excel - 使用查找表中的值导出 Access 数据库

vba - 连接 PowerPoint 和 Excel

vba - 由于 Private Declare 语句的位置而导致编译错误

sql - MS Access VBA - 使用 SELECT INTO 创建新表并添加记录