如何将单元格的填充图案复制到形状?

问题描述 投票:0回答:1

我一直在编写代码,该代码将复制单元格的颜色并将其粘贴到相关的形状。我能够复制颜色。但是,复制单元格的填充样式似乎更为复杂。我面临的问题是,单元格的图案参数例如是“ xlLightHorizo​​ntal”,形状的相同图案是“ msoPatternNarrowHorizo​​ntal”。两者都绘制相同的填充图案,但名称不同。

我如何复制单元格的颜色和填充图案:

modelText(3, 1) = Sheets("Orders").Cells(row, j + 1).Interior.Color
modelText(3, 2) = Sheets("Orders").Cells(row, j + 1).Interior.Pattern
modelText(3, 3) = Sheets("Orders").Cells(row, j + 1).Interior.PatternColor

我如何将颜色和填充图案分配给形状:

 With Selection.ShapeRange.Fill
        .ForeColor.RGB = modelText(3, 1)
        .BackColor.RGB = modelText(3, 3)
        .Patterned (msoPatternLightHorizontal)
 End With

注意:

[Cells(row, j + 1).Interior.Pattern返回xlLightHorizontal

哪里

[ShapeRange.Fill.Patterned不接受xlLightHorizontal作为输入参数

无论如何,您是否知道将单元格的填充图案复制到形状上?

excel vba design-patterns cell shapes
1个回答
0
投票

我试图找到一种解决方案。看起来这两组枚举不匹配。我希望您确实要使用的模式集非常有限。在这种情况下,我将对成对的表(数字相同或至少相似的模式)进行转换。我没有更好的主意。抱歉。

https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.core.msopatterntype?view=office-piahttps://docs.microsoft.com/en-us/dotnet/api/microsoft.office.interop.excel.constants?view=excel-pia

© www.soinside.com 2019 - 2024. All rights reserved.