如何使用 Shapes.AddShape 方法添加相机对象

发布于 2024-12-17 00:27:05 字数 465 浏览 2 评论 0原文

如果我录制宏。我看到这段代码。

Selection.Copy
ActiveSheet.Shapes.AddShape(, 480.75, 171#, 63#, 63#).Select
ActiveSheet.Shapes.Range(Array("Picture 2")).Select
Application.CutCopyMode = False

当我查看 MsoAutoShapeType 枚举时,我看不到相机对象。

如果我更改任何值,它会给出异常... (, 480.75, 171#, 63#, 63#) 文档说这些值是顶部、左侧、宽度和高度...

我想编写一个方法,可以在我给定的任何范围内创建相机对象,

Sub TakePhoto(myRange As String, myPicture As String)

我怎样才能实现这一点?

If I record the macro. I see this code.

Selection.Copy
ActiveSheet.Shapes.AddShape(, 480.75, 171#, 63#, 63#).Select
ActiveSheet.Shapes.Range(Array("Picture 2")).Select
Application.CutCopyMode = False

When I looked at the MsoAutoShapeType enumaration I couldn't see camera object.

And if I change any value it gives exception... (, 480.75, 171#, 63#, 63#)
the documentation says that these values are top,left,width and height ...

I want to write a method that can create camera objects any range I give

Sub TakePhoto(myRange As String, myPicture As String)

How can I achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红衣飘飘貌似仙 2024-12-24 00:27:05

试试这个:

Sub TakePhoto(rngSource As Excel.Range, rngTarget As Excel.Range)
Dim ws As Excel.Worksheet
Dim shpPicture As Excel.Shape

Set ws = rngTarget.Parent
rngSource.Copy
ws.Pictures.Paste Link:=True
Set shpPicture = ws.Shapes(ws.Shapes.Count)
With shpPicture
    .Top = rngTarget.Top
    .Left = rngTarget.Left
End With
End Sub

这样称呼它:

Sub test()
TakePhoto Sheet2.Range("A1:C4"), Sheet1.Range("c5")
End Sub

Try this:

Sub TakePhoto(rngSource As Excel.Range, rngTarget As Excel.Range)
Dim ws As Excel.Worksheet
Dim shpPicture As Excel.Shape

Set ws = rngTarget.Parent
rngSource.Copy
ws.Pictures.Paste Link:=True
Set shpPicture = ws.Shapes(ws.Shapes.Count)
With shpPicture
    .Top = rngTarget.Top
    .Left = rngTarget.Left
End With
End Sub

Call it like this:

Sub test()
TakePhoto Sheet2.Range("A1:C4"), Sheet1.Range("c5")
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文