vba - Excel VBA : Positioning and Alignment of Shapes

标签 vba excel

我正在尝试使用一些形状(如图表和图片)的 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是顶部对齐。 WidthHeight - 好吧,你可以弄清楚!

更多信息请访问 http://peltiertech.com/Excel/ChartsHowTo/QuickChartVBA.html

关于vba - Excel VBA : Positioning and Alignment of Shapes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12816728/

相关文章:

.net - 带有 VBA 的 WinSCP .NET 程序集抛出 ActiveX 组件无法创建对象

vba - Excel VBA 如果值为空则匹配

java - excel中如何找出合并单元格下对齐的单元格

excel - "Cannot insert object"将 PDF 文件/对象插入 Microsoft Excel 时出错

vba - 使用 VBA 将电子表格传输到 Access 数据库

vba - 如何找到工作簿的最大行数 - vba

excel - 使用 ADO 从 Excel 读取数据的空值

javascript - 将 HTML 文档的 javascript 部分中的字段提取到表中?地理坐标

Excel公式提取2个特定字符之间的字符串

excel - 视觉基础。错误返回 1