|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 zjdh 于 2012-8-4 13:40 编辑
Private Sub CommandButton4_Click() '按钮粘贴
On Error GoTo Err
Set D = New DataObject
D.GetFromClipboard
X = UBound(Split(Replace(D.GetText(1), vbCrLf, vbTab), vbTab))
If Abs(Selection.Cells.Count - X) > 0 Then MsgBox "请选择整个粘贴区域!": Exit Sub
Set S = Application.Intersect(Selection, Range("G:H"))
If Not S Is Nothing Then MsgBox "你选择的区域不得粘贴!": Exit Sub
Set S = Application.Intersect(Selection, Range("J:L"))
If Not S Is Nothing Then MsgBox "你选择的区域不得粘贴!": Exit Sub
Set S = Application.Intersect(Selection, Range("N:P"))
If Not S Is Nothing Then MsgBox "你选择的区域不得粘贴!": Exit Sub
Set S = Application.Intersect(Selection, Range("R:T"))
If Not S Is Nothing Then MsgBox "你选择的区域不得粘贴!": Exit Sub
Set S = Application.Intersect(Selection, Rows(UsedRange.Rows.Count + 1))
If Not S Is Nothing Then MsgBox "你选择的区域超过了表格区域": Exit Sub
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Exit Sub
Err:
If Application.CutCopyMode = False Then
MsgBox "您还没复制,或请重新复制。"
Else
MsgBox "如果粘贴整行或整列,请注意粘贴位置;" & Chr(10) & "另外,本命令在剪切模式下不可使用。"
End If
End Sub |
|