1

你有没有机会帮我把这两个工作表更改结合起来?我想对一个范围强制使用大写字母并防止所有复制/粘贴。

Private Sub Worksheet_Change(ByVal Target As Range)

    Dim UndoList As String

    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With

    On Error GoTo ErrExit
    UndoList = Application.CommandBars("Standard").Controls("&Undo").List(1)
    If Left(UndoList, 5) = "Paste" Or UndoList = "Auto Fill" Then
        MsgBox "Copy / paste is not permitted" & vbCr & _
               "- Creator"
        With Application
            .Undo
            .CutCopyMode = False
        End With
        Target.Select
    End If

ErrExit:
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
End Sub

上面是防止复制/过去,下面是大写。

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not (Application.Intersect(Target, Range("AB26:QE124")) _
      Is Nothing) Then
        With Target
            If Not .HasFormula Then
                Application.EnableEvents = False
                .Value = UCase(.Value)
                Application.EnableEvents = True
            End If
        End With
    End If
End Sub
4

1 回答 1

2

因此,保持条件只为单元格制作大写,Range("AB26:QE124")可以使用下一个合并代码:

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim UndoList As String

    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With

    On Error GoTo ErrExit
    UndoList = Application.CommandBars("Standard").Controls("&Undo").List(1)
    If left(UndoList, 5) = "Paste" Or UndoList = "Auto Fill" Then
        MsgBox "Copy / paste is not permitted" & vbCr & _
               "- Creator"
        With Application
            .Undo
            .CutCopyMode = False
        End With
        Target.Select
    End If

    'The UperCase part______________________________________________
    If Not (Application.Intersect(Target, Range("AB26:QE124")) _
                                                    Is Nothing) Then
        With Target
            If Not .HasFormula Then
                Application.EnableEvents = False
                .Value = UCase(.Value)
                Application.EnableEvents = True
            End If
        End With
    End If
    '_______________________________________________________________

ErrExit:
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
End Sub
于 2020-01-26T12:26:13.800 回答