所有启用宏的Excel工作表最终都损坏

时间:2019-05-06 14:16:36

标签: excel vba corruption

每当我启用下面的宏时,工作表就会损坏。 我已经将数据复制并粘贴到一本全新的书中。

保存并重新打开后,我收到“您想尽我们最大的努力进行恢复吗?”对话框,并重置启用宏的工作表上的格式,并禁用宏。

我在VBA编辑器中看到了这一点,它看起来像“表2”被视为某个未知对象,并为“第一条”提供了另一个工作表变量。

enter image description here

有人可以帮忙吗?

Private Sub Worksheet_Activate()
        Dim vars As Variant
        vars = Array("<CLICK FOR VARIANT LIST>", "sensitive content hidden")

        Dim sVars As String
        sVars = Join(vars, ",")

        With Range("E6").Validation
            .Delete
            .Add Type:=xlValidateList, Formula1:=sVars
        End With

        vars = Array("NOT SET", "SET")
        sVars = Join(vars, ",")

        With Range("I6").Validation
            .Delete
            .Add Type:=xlValidateList, Formula1:=sVars
        End With

End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim vars As Variant
    vars = Array("<CLICK FOR VARIANT LIST>", "sensitive content hidden")

    If Target.Address = Range("E6").Address Then
        Dim i As Integer
        i = Application.Match(Range("E6").Value, vars, False)
        If i = 1 Then
            Range("A11:A109").EntireRow.Hidden = True
            Range("D111:D112").EntireRow.Hidden = False
        Else
            Range("A11:A109").EntireRow.Hidden = False
            Range("D111:D112").EntireRow.Hidden = True
            Range("A1").Value = i + 6
        End If

        'SXM/HD
        If i = 0 _
        Or Range("E6").Value = "sensitive content hidden" Then
            Range("hd_sw_row").EntireRow.Hidden = False
            Range("hd_pn_row").EntireRow.Hidden = False
            Range("sxm_pn_row").EntireRow.Hidden = False
            Range("sxm_function_row").EntireRow.Hidden = False
        Else
            Range("hd_sw_row").EntireRow.Hidden = True
            Range("hd_pn_row").EntireRow.Hidden = True
            Range("sxm_pn_row").EntireRow.Hidden = True
            Range("sxm_function_row").EntireRow.Hidden = True
        End If

        'DAB
        If i = 0 _
        Or Range("E6").Value = "sensitive content hidden"
        Then
            Range("dab_sw_row").EntireRow.Hidden = False
            Range("dab_pn_row").EntireRow.Hidden = False
            Range("dab_function_row").EntireRow.Hidden = False
        Else
            Range("dab_sw_row").EntireRow.Hidden = True
            Range("dab_pn_row").EntireRow.Hidden = True
            Range("dab_function_row").EntireRow.Hidden = True
        End If

        'GPS
        If i = 0 _
        Or Range("E6").Value = "sensitive content hidden"
        Then
            Range("gps_sw_row").EntireRow.Hidden = False
            Range("gps_pn_row").EntireRow.Hidden = False
            Range("gps_function_row").EntireRow.Hidden = False
        Else
            Range("gps_sw_row").EntireRow.Hidden = True
            Range("gps_pn_row").EntireRow.Hidden = True
            Range("gps_function_row").EntireRow.Hidden = True
        End If
    End If
End Sub

0 个答案:

没有答案