我正在尝试使用一些形状(如图表和图片)的 Excel 表格制作可打印的报告。我可以使用以下代码将图表放在工作表上:
oSheetReport.Range("A51").Select()
Dim oChart1 As Excel.Shape
oChart1 = oSheetReport.Shapes.AddChart()
oChart1.Chart.ChartType = Excel.XlChartType.xlLine
oChart1.Chart.SetSourceData(Source:=oSheet.UsedRange)
oSheetReport.Range("A70").Select()
oChart1 = oSheetReport.Shapes.AddChart()
oChart1.Chart.ChartType = Excel.XlChartType.xlColumnStacked
oChart1.Chart.SetSourceData(Source:=oSheet.UsedRange)
oSheetReport.Range("A100").Select()
oChart1 = oSheetReport.Shapes.AddChart()
oChart1.Chart.ChartType = Excel.XlChartType.xlColumnStacked100
oChart1.Chart.SetSourceData(Source:=oSheet.UsedRange)
但是定位和对齐失败了,这让我的报告看起来很难看。有没有更好的方法来实现这一点?
最佳答案
要在一个步骤中添加、定位和对齐,您可以使用以下命令:
Set oChart1 = ActiveSheet.ChartObjects.Add _
(Left:=250, Width:=375, Top:=75, Height:=225)
Left
是左对齐和Top
是顶部对齐。 Width
和 Height
- 好吧,你可以弄清楚!更多信息请访问 http://peltiertech.com/Excel/ChartsHowTo/QuickChartVBA.html
关于vba - Excel VBA : Positioning and Alignment of Shapes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12816728/