Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 添加/删除行但仅添加/删除一次时的VBA消息框_Excel_Vba - Fatal编程技术网

Excel 添加/删除行但仅添加/删除一次时的VBA消息框

Excel 添加/删除行但仅添加/删除一次时的VBA消息框,excel,vba,Excel,Vba,我试图创建一个消息框,告诉您在添加/删除行之前打开一些其他文件,以确保引用不会丢失。下面的内容有效,但每次添加一行时都有效,是否可以在添加/删除第一行时仅显示一次?非常感谢您的帮助 Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = Target.EntireRow.Address Then MsgBox "If File 1 and File 2 are not open, p

我试图创建一个消息框,告诉您在添加/删除行之前打开一些其他文件,以确保引用不会丢失。下面的内容有效,但每次添加一行时都有效,是否可以在添加/删除第一行时仅显示一次?非常感谢您的帮助

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = Target.EntireRow.Address Then
    MsgBox "If File 1 and File 2 are not open, please close this workbook without saving and open all files first."
    End If
End Sub

您可以做的是声明一个
Boolen
类型的公共变量。参见下面的代码。打开文件后,消息将显示一次。若文件被关闭并重新打开,则再次显示该消息一次

Public StopPopMsg As Boolean

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not StopPopMsg Then
        If Target.Address = Target.EntireRow.Address Then
            MsgBox "If File 1 and File 2 are not open, please close this workbook without saving and open all files first."
            StopPopMsg = True
        End If
    End If
End Sub

神奇的哈伦,工作得很有魅力。非常感谢您的快速回答。@FBeckenbauer4很高兴知道!