VBA Excel将多个形状复制到剪贴板 [英] VBA Excel copy multiple shapes to clipboard

查看:304
本文介绍了VBA Excel将多个形状复制到剪贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有四个形状的Excel工作表和几个用于运行宏的按钮.这些形状分别命名为topCircle,leftCircle,rightCircle和& midCircle.

I have an Excel sheet with four shapes and a couple of buttons to run macros. The shapes are named topCircle, leftCircle, rightCircle & midCircle.

想要其中一个按钮来运行宏,以将四个形状复制到剪贴板,以便粘贴到其他Office文档中.

Wanting one of the buttons to run a macro that copies the four shapes to clipboard, for pasting into other Office docs.

浏览过各种MSDN文章(例如 https://msdn .microsoft.com/en-us/library/office/ff940375.aspx ),但遇到了麻烦.为了模仿链接文章中的示例,我这样写:

Have been though various MSDN articles (like https://msdn.microsoft.com/en-us/library/office/ff940375.aspx) but having trouble. Trying to imitate the example on the linked article, I wrote this:

Set myDocument = Worksheets("Overall")

myDocument.Shapes.Range(Array("leftCircle", "rightCircle", "topCircle", "midCircle")).Copy

但是出现错误对象不支持此属性或方法".还尝试了其他一些没有运气的事情.关于如何使它起作用的任何想法?干杯!

But getting an error "Object doesn't support this property or method". Have also tried a few other things without luck. Any ideas as to how to get this to work? Cheers!

推荐答案

似乎要从Excel工作表中复制多个形状,您有3个选择:

It seems that to copy multiple shapes from an Excel worksheet you have 3 options:

选项1 :首先使用Select选择所有Shapes,然后复制Selection:

Option 1: Use Select first to select all Shapes, and then copy the Selection :

myDocument.Shapes.Range(Array("leftCircle", "rightCircle", "topCircle", "midCircle")).Select
Selection.Copy

选项2 :使用Group对所有选定形状进行分组,然后将它们复制在一起,然后使用Ungroup将它们拆分回去:

Option 2: Use the Group to group all selected shapes, then copy them together, and afterwards use the Ungroup to split them back:

With myDocument.Shapes.Range(Array("leftCircle", "rightCircle", "topCircle", "midCircle"))
    .Group.Copy
    ' paste to wherever you want

    .Ungroup
End With

选项3 :使用For Each MyShape In myDocument.Shapes循环浏览myDocument工作表中的所有Shapes,如果它可以计算出您想要的Shape.Name之一,则将其复制:

Option 3: use For Each MyShape In myDocument.Shapes to loop through all Shapes in myDocument worksheet, and if it mathces one of the Shape.Name you wanted it, copy it:

Dim MyShape     As Shape

For Each MyShape In myDocument.Shapes
    Select Case MyShape.Name
        Case "leftCircle", "rightCircle", "topCircle", "midCircle"
            MyShape.Copy
            ' paste to wherever you want

    End Select
Next MyShape

这篇关于VBA Excel将多个形状复制到剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆