[英]Copy/paste graph to a new sheet and resize
I would like to copy a graph and paste it to a new sheet at a specific location and then resize it. 我想复制一个图形并将其粘贴到特定位置的新表中,然后调整其大小。
This code just resizes the original graph: 这段代码只是调整了原始图形的大小:
Dim ws as worksheet
set ws = worksheets("Sheet2")
Sheets("Sheet1").Select
Sheets("Sheet1").ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Copy
ws.Paste Destination:=ws.Range("B17")
With ActiveChart.Parent
.Height = 100 ' resize
.Width = 250 ' resize
End With
I tried to record a macro. 我试图记录一个宏。 It would activate the destination chart with a assigned chart name first (such as "Chart 6" in the below codes) and then do the resize.
它将首先使用指定的图表名称激活目标图表(例如以下代码中的“图表6”),然后进行调整大小。 In my case, the chart name changes all the time so I cannot code it in the macro.
就我而言,图表名称一直在变化,因此我无法在宏中对其进行编码。
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.copy
Sheets("Sheet2").Select
Range("C3").Select
ActiveSheet.Paste
ActiveSheet.ChartObjects("Chart 6").Activate
With ActiveChart
.Height = 100 ' resize
.Width = 250 ' resize
End With
Sub test()
Dim ws As Worksheet
Dim Chrt1 As ChartObject
Dim chrt2 As ChartObject
Set ws = Worksheets("Sheet2")
Set Chrt1 = Sheets("Sheet1").ChartObjects(1)
Chrt1.Copy
ws.Paste Destination:=ws.Range("B17")
Set chrt2 = ws.ChartObjects(1)
With chrt2.Chart.Parent
.Height = 100 ' resize
.Width = 250 ' resize
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.