简体   繁体   English

使用VBA根据Excel中的点名称自动将照片添加到甜甜圈图点

[英]Automatically adding photos to donut chart points based on point name in Excel using VBA

I'm completely new to VBA, and I'm working on a project to draw a concentric donut chart showing a number of different brands. 我对VBA完全陌生,我正在一个项目上绘制同心的甜甜圈图,该图显示了许多不同的品牌。 I'm trying to automatically attach the brand logos to the outer ring of the donut chart. 我正在尝试将品牌徽标自动附加到甜甜圈图的外圈。 My idea is to have one loop that first names each point of the series with the brand name, and a second loop that refers to a file location that contains the logos, finds corresponding logo, and pastes that logo into the point. 我的想法是有一个循环,该循环首先用品牌名称命名系列的每个点,然后再循环一个,该循环引用包含徽标的文件位置,找到对应的徽标,然后将该徽标粘贴到该点中。

I found some previous questions/answers about how to name points on a pie chart, but I can't seem to get any of them to work on my donut chart. 我之前找到了一些有关如何在饼图上命名点的问题/答案,但似乎无法在甜甜圈图上使用它们。 I managed to copy a single named picture from the file location into a single chart point using 我设法使用以下命令从文件位置将单个命名图片复制到单个图表点中

ActiveChart.SeriesCollection("Brand").Points(1).Format.Fill.UserPicture ("C:...\Abrand.JPG")

but this isn't very sophisticated and I don't know how to scale it up to automatically paste any logo into a corresponding point. 但这不是很复杂,我也不知道如何按比例放大以自动将任何徽标粘贴到相应的位置。

Any help would be greatly appreciated, and as I'm very new if you could annotate what you've done so I can learn that would be very much appreciated too! 任何帮助将不胜感激,并且如果您能注释您所做的事情,那么我还是一个新手,因此我也将学习到非常感谢!

If you can map your label values to your logo names you can do something like this: 如果可以将标签值映射到徽标名称,则可以执行以下操作:

Dim BrandChart As Chart
Set BrandChart = ActiveChart

Dim Brand
Dim i As Integer

i = 0
For Each Brand In BrandChart.SeriesCollection("Brand").XValues
    i = i + 1
    BrandChart.SeriesCollection("Brand").Points(i).Format.Fill.UserPicture "c:\...\" & Brand & ".jpg"
Next

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM