Sub FitChartToRange()
Dim cht As Chart
Dim rng As Range
'賦值對象到變量
Set cht = ActiveChart
Set rng = ActiveSheet.Range('B2:J18')
'移動并調(diào)整圖表大小
cht.Parent.Left = rng.Left
cht.Parent.Top = rng.Top
cht.Parent.Width = rng.Width
cht.Parent.Height = rng.Height
End Sub
Sub ExportSingleChartAsImage()
Dim imagePath As String
Dim cht As Chart
imagePath = 'C:\完美Excel\myImage.png'
Set cht = ActiveChart
'導(dǎo)出圖表
cht.Export (imagePath)
End Sub
Sub ResizeAllCharts()
Dim chtHeight As Long
Dim chtWidth As Long
'創(chuàng)建遍歷圖表對象的變量
Dim chtObj As ChartObject
'獲取第一個選擇的圖表的大小
chtHeight = ActiveChart.Parent.Height
chtWidth = ActiveChart.Parent.Width
For Each chtObj In ActiveSheet.ChartObjects
chtObj.Height = chtHeight
chtObj.Width = chtWidth
Next chtObj
End Sub
聯(lián)系客服