复制范围但隐藏内部形状

时间:2015-05-01 13:55:16

标签: excel vba shapes

是否可以通过VBA复制Excel中的范围,但其中有形状,隐藏? 我试图隐藏形状,选择范围,然后再次显示它们但选择“保持打开”可以这么说,直到它被粘贴,所以形状出现。是否可以在再次显示之前立即将其放入剪贴板? 这就是我的尝试:

Sub copyIt()
    lastRow = ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row
    lastColumn = ActiveSheet.Cells(2, Columns.Count).End(xlToLeft).Column

    For Each Shape In ActiveSheet.Shapes
    Shape.Visible = msoFalse
    Next

    ActiveSheet.Range(Cells(1, 1), Cells(lastRow, lastColumn)).Copy

    For Each Shape In ActiveSheet.Shapes
    Shape.Visible = msoTrue
    Next

End Sub

1 个答案:

答案 0 :(得分:1)

尽量避免在副本粘贴之间放置任何代码。假设我们从:

开始

enter image description here

我们会:

  • 隐藏形状
  • 执行复制/粘贴
  • 验证形状是否隐藏
  • 取消隐藏形状
  • 验证形状是否与单元格一起复制

    Sub Shapee()     Dim r1 As Range,r2 As Range     昏暗作为形状     设置r1 =范围(" A1:F14")     设置r2 =范围(" H1")

    For Each Sh In ActiveSheet.Shapes
        Sh.Visible = msoFalse
    Next
    
    r1.Copy r2
    MsgBox "INSPECT SHEET"
    
    For Each Sh In ActiveSheet.Shapes
        Sh.Visible = msoTrue
    Next
    MsgBox "INSPECT SHEET AGAIN"
    

    End Sub