Excel VBA:使用基于单元格值的图像填充堆叠图(和树图 - 图)

时间:2017-03-14 13:14:02

标签: excel vba excel-vba diagram

我尝试使用基于单元格值的图像填充堆叠的Excel图表。我可以为第一列做到这一点,但不能用于第二列。

这是一个例子。我想用基于B列值的图像填充橙色区域

Image: stacked diagram

这是VBA代码,我如何用图像填充第一列:

Sub fill_with_image()
    With Sheets("Sheet1").ChartObjects(1).Chart.SeriesCollection(1)
        Set vAddress = ActiveSheet.Range(Split(Split(.Formula, ",")(1), "!")(1))
        For i = 1 To vAddress.Cells.Count
            imagefile = Cells(i + 1, 1).Value
            .Points(i).Format.Fill.UserPicture (imagefile & ".png")
        Next i
    End With
End Sub

我的问题的第二部分:我找不到任何文档如何用图像填充树形图。知道它是否可能?

Image Treemap-Diagram

1 个答案:

答案 0 :(得分:1)

只需循环选择SeriesCollection(2)

即可
Sub fill_with_image()
Dim j as integer    
For j = 1 to 2
    With Sheets("Sheet1").ChartObjects(1).Chart.SeriesCollection(j)
    Set vAddress = ActiveSheet.Range(Split(Split(.Formula, ",")(1), "!")(1))
    For i = 1 To vAddress.Cells.Count
        imagefile = Cells(i + 1, 1).Value
        .Points(i).Format.Fill.UserPicture (imagefile & ".png")
    Next i
    End With
Next j
End Sub