|
楼主 |
发表于 2012-8-19 10:32
|
显示全部楼层
zjdh 发表于 2012-8-18 08:05
最后一句没有测试
把
If R = "" Then Exit Sub
为何还是不能实现粘贴呢?代码如下:
- Sub action_taken() '按钮粘贴
- On Error GoTo Err
- Set d = New DataObject
- d.GetFromClipboard
- Y = UBound(Split(d.GetText(1), vbCrLf))
- X = UBound(Split(d.GetText(1), vbTab)) / Y
- X1 = Selection.Column
- Y1 = Selection.Row
- Z = ActiveSheet.UsedRange.Rows.Count
- If Y + Y1 > Z Then MsgBox "你粘贴的区域超过了表格区域": Exit Sub
- NM = UCase(ActiveSheet.Name)
- '第一组
- SH1 = Array("SHEET1", "SHEET3") '第一组工作表
- R1 = Array(7, 8, 10, 11, 12, 14, 15, 16, 18, 19, 20) '第一组不可粘贴列号
- For i = 0 To UBound(SH1)
- If SH1(i) = NM Then R = R1: Exit For
- Next
- '第二组
- SH2 = Array("SHEET2", "SHEET4")
- R2 = Array(10, 11, 12, 14, 15, 16, 18, 19, 20)
- For i = 0 To UBound(SH2)
- If SH2(i) = NM Then R = R2: Exit For
- Next
- '........其他组
- If Not IsArray(R) Then Exit Sub
- For i = X1 To X + X1
- For j = 0 To UBound(R)
- If R(j) = i Then MsgBox "你选择的区域不得粘贴!": Exit Sub
- Next
- Next
- Selection.PasteSpecial Paste:=xlPasteValues
- Exit Sub
- Err:
- If Application.CutCopyMode = False Then
- MsgBox "您还没复制,或请重新复制。"
- Else
- MsgBox "如果粘贴整行或整列,请注意粘贴位置;" & Chr(10) & "另外,本命令在剪切模式下不可使用。"
- End If
- End Sub
复制代码
|
|