我想复制图形并将其粘贴到特定位置的新工作表中,然后调整其大小。
此代码只是调整原始图形的大小:
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
我试图记录一个宏。它将首先使用指定的图表名称激活目标图表(例如以下代码中的“图表6”),然后进行调整大小。就我而言,图表名称一直在变化,因此我无法在宏中对其进行编码。
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
答案 0 :(得分:1)
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