我有一个使用日期单元格通过VB.NET生成和验证excel单元格值的方案,当我在单元格中键入一个值时,一切正常,但是当我在单元格中复制粘贴它接受的任何字符串值时永远不会验证。
问题:我想从VB.NET中限制单元格中的粘贴(Ctrl-V)。我怎样才能做到这一点?
这是我的代码:
worksheet.Range(DateRange).Validation.Delete()
worksheet.Range(DateRange).Validation
.Add(ValidationType.Date, ValidationAlertStyle.Stop,
ValidationOperator.Greater, dt, Nothing)
worksheet.Range(DateRange).NumberFormat = "mm/dd/yyyy"
worksheet.Range(DateRange).Validation.IgnoreBlank = True
worksheet.Range(DateRange).Validation.InputTitle = "Excel Validation"
worksheet.Range(DateRange).Validation.ErrorTitle = "Error in Date"
答案 0 :(得分:0)
这是我发现的东西
Private Sub Workbook_Activate()
Application.CutCopyMode = False
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
End Sub
Private Sub Workbook_Deactivate()
Application.CellDragAndDrop = True
Application.OnKey "^c"
Application.CutCopyMode = False
End Sub
Private Sub Workbook_WindowActivate(ByVal Wn As Window)
Application.CutCopyMode = False
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
End Sub
Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
Application.CellDragAndDrop = True
Application.OnKey "^c"
Application.CutCopyMode = False
End Sub
Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Cancel = True
MsgBox "Right click menu deactivated." & vbCrLf & _
"Cannot copy or ''drag & drop''.", 16, "For this workbook:"
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Application.CutCopyMode = False
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
Application.CutCopyMode = False
End Sub
Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
Application.CutCopyMode = False
End Sub