更改系列的线条透明度而不影响 Excel VBA 中的标记透明度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9525118/
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-11 15:24:48  来源:igfitidea点击:

Changing line transparency of a series without affecting marker transparency in Excel VBA

excelvbaexcel-vbatransparency

提问by user1167662

I am writing a macro in VBA for excel in which I would like to change the transparency of the lines connecting markers in a series but leave the transparency of the markers in the series the same.

我正在 VBA 中为 excel 编写一个宏,我想在其中更改连接系列中标记的线条的透明度,但保持系列中标记的透明度相同。

To specify: the chart is a scatter plot. I would like the markers for a series to be opaque/zero transparency and for the lines in the series to be 75% transparent.

要指定:图表是散点图。我希望系列的标记为不透明/零透明度,并且系列中的线条为 75% 透明。

I have adjsuted the transparency of the lines by using myseries.format.line.transparency = 0.75but this changes the marker transparency as well.

我已经通过使用myseries.format.line.transparency = 0.75调整了线条的透明度, 但这也会改变标记的透明度。

does anyone know of a way I can change the transparency of the two separately? I imagine there is a member/property to do what I want, but I cannot find it.

有谁知道我可以分别改变两者透明度的方法吗?我想有一个成员/财产可以做我想做的事,但我找不到它。

thanks in advance for any help!

在此先感谢您的帮助!

回答by j boschiero

This answer isn't going to make you very happy.

这个答案不会让你很高兴。

I've looked into this before and the information i've gotten is that this simply isn't a parameter that you can specify through VBA. It looks like you can access marker style, size, background color and foreground color, and that's about it.

我之前研究过这个问题,我得到的信息是这根本不是您可以通过 VBA 指定的参数。看起来您可以访问标记样式、大小、背景颜色和前景色,仅此而已。

Maybe MS didn't think anyone would ever want to mess with that.

也许 MS 认为没有人会想要惹恼它。

One thing you could try is applying a custom chart format, but if you have variable numbers and/or orders of series then that may not work.

您可以尝试的一件事是应用自定义图表格式,但如果您有可变数字和/或系列订单,那么这可能不起作用。

 mychart.ApplyChartTemplate ("filepath\filename.crtx")

Something like that, where mychart is already set equal to the chart you want to format.

类似的东西,其中 mychart 已经设置为等于您要格式化的图表。

Again, maybe not of any use to you, best i could think of.

再说一次,也许对你没有任何用处,我能想到的最好。

回答by Alain

You guys didn't dig hard enough.

你们挖的不够深。

SeriesCollection(i).Format.Line.Transparency

SeriesCollection(i).Format.Line.Transparency

will work ifthe SeriesObject is in a certain state. The original 'automatic' line style state prevents this vba from doing anything at first, but if you simply precede it by setting certain other properties on the line format first, then the transparency will take. The following worked for me:

如果SeriesObject 处于某种状态,它将起作用。原始的“自动”线型状态一开始会阻止此 vba 执行任何操作,但是如果您只是通过先在线格式上设置某些其他属性来执行它,那么透明度将需要。以下对我有用:

For Each obj In myChart.SeriesCollection
    obj.Format.Line.DashStyle = 1
    obj.Format.Line.Transparency = 0.65
Next obj

DashStyle = 1sets the line style to 'Solid' (as opposed to dashed, dotted, etc.) and has the side effect of freeing up the series format to have the transparency set. I don't know for sure why it works, but it does.

DashStyle = 1将线条样式设置为“实线”(与虚线、虚线等相反),并且具有释放系列格式以设置透明度的副作用。我不确定它为什么会起作用,但确实如此。

回答by Mooloo

Sorry, my mistake. I read the question slightly wrong.

抱歉,是我的错。我读这个问题有点错误。

I find that if I start the line with no markers, then turning transparency separately doesn't turn the markers on and off.

我发现如果我开始没有标记的线,那么单独打开透明度不会打开和关闭标记。

回答by Julio

Try this:

尝试这个:

activechart.SeriesCollection(1).format.fill.transparency=0.5