简体   繁体   English

有人可以提供为什么不能在 Excel VBA 中将 `Interior.Color` 属性从一个范围分配到另一个范围的技术原因吗?

[英]Can someone provide the technical reason why the `Interior.Color` property can't be assigned from one range to another in Excel VBA?

I've seen this link describing using the clipboard to transfer formats (and this is probably what I'll end up having to do), but I'd like to know the technical reason why values can be assigned by reference and formats can't.我已经看到这个链接描述使用剪贴板传输格式(这可能是我最终不得不做的事情),但我想知道为什么可以通过引用分配值而格式可以的技术原因'吨。

In other words, why does this work...换句话说,为什么这行得通……

Sheets("Sheet2").Range("A1:B10").Value = Sheets("Sheet1").Range("D1:E10").Value

and this fail?...这失败了?...

Sheets("Sheet2").Range("A1:B10").Interior.Color = Sheets("Sheet1").Range("D1:E10").Interior.Color

In short, Interior.Color only returns one color, not an array of colors.简而言之, Interior.Color只返回一种颜色,而不是一组颜色。

So this only works if the Interior.Color is the same for all of the source target cells.因此,这仅适用于所有源目标单元格的Interior.Color相同的情况。

Since Interior.Color doesn't return an array of differing colors, it will return 0 if the colors don't match across the source target cells.由于Interior.Color不返回不同颜色的数组,如果颜色在源目标单元格中​​不匹配,它将返回0

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

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