Excel VBA,用于更改雷达图上的标记大小、颜色和透明度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27361262/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 05:26:46  来源:igfitidea点击:

Excel VBA for changing marke size, color, and transparency on a radar plot

excelvbaradar-chart

提问by Adam

I'm being stonewalled by VBA when attempting to assign a custom marker color AND transparency level on a radar chart. I've read there are some issues with order, but no matter where I try the .transparency parameter, I get the following error: Object doesn't support this property or method.

尝试在雷达图上分配自定义标记颜色和透明度级别时,我被 VBA 挡住了。我读过顺序有一些问题,但无论我在哪里尝试 .transparency 参数,我都会收到以下错误:对象不支持此属性或方法。

If I comment out the .transparency line in the following code, I get a great radar plot with markers colored by values in rngColors. I would just like to make them transparent so the underlying line plots come through as well. Any help or advice would be greatly appreciated.

如果我在下面的代码中注释掉 .transparency 行,我会得到一个很好的雷达图,其中标记由 rngColors 中的值着色。我只是想让它们透明,这样底层的线图也能通过。任何帮助或建议将不胜感激。

Regards, Adam

问候, 亚当

Sub colorPoints()

'Must select chart when running macro

  Dim x As Long
  Dim rngColors As Range

  Set rngColors = Range("H8:H57") 'set range of RGB color

  For x = 1 To ActiveChart.SeriesCollection(1).Points.Count
    With ActiveChart.SeriesCollection(1).Points(x)

        .Format.Fill.Solid
        .MarkerBackgroundColor = RGB(212, 142, rngColors(x))
        .transparency = 0.5 <-Error: 'Object doesn't support this property or method.'

    End With
Next

End Sub

EDIT: Thanks to the link in the comments, the following code worked for me when run as a separate macro after assigning color. It's tricky though, and I don't know why. First I need to run the transparency code (below), then comment out .Solid, then run the color code (above), then the transparency code again (below), then it works. Yikes! I'm not too worried about optimizing now, but this seems to work regularly:

编辑:感谢评论中的链接,以下代码在分配颜色后作为单独的宏运行时对我有用。不过这很棘手,我不知道为什么。首先我需要运行透明度代码(下面),然后注释掉 .Solid,然后运行颜色代码(上面),然后再次运行透明度代码(下面),然后它就可以工作了。哎呀!我现在不太担心优化,但这似乎经常起作用:

Sub transcheck()

' transcheck Macro

Dim cht As Chart
Dim Ser As Series
Dim lngIndex As Long
Dim lngChartType As XlChartType

Set cht = ActiveSheet.ChartObjects(1).Chart
Set Ser = cht.SeriesCollection(1)
lngChartType = Ser.ChartType
Ser.ChartType = xlColumnClustered

For lngIndex = 1 To 50
 With Ser.Format.Fill
   .Solid
   .Visible = True
   .transparency = 0.5
 End With

Ser.ChartType = lngChartType
Next
End Sub

采纳答案by Chrismas007

The information I found has proper syntax of .Format.Fill.Transparency = 0.5http://answers.microsoft.com/en-us/office/forum/office_2007-excel/macro-to-change-the-transparency-of-markers-in-a/6a9964a7-30ad-4412-a48f-2334e4ecd63d

我发现的信息具有http://answers.microsoft.com/en-us/office/forum/office_2007-excel/macro-to-change-the-transparency-of-markers-in-a/6a9964a7- 的正确语法.Format.Fill.Transparency = 0.530ad-4412-a48f-2334e4ecd63d

Although there is discussion of bugs with that coding depending on your Excel version: http://www.mediafire.com/file/j2tnzlcizzm/05_09_10b.pdf

尽管根据您的 Excel 版本讨论了该编码的错误:http: //www.mediafire.com/file/j2tnzlcizzm/05_09_10b.pdf