VBA,Excel如何设置特定样式而不使用它们的名称?

prz*_*_li 5 excel formatting user-interface vba

VBA,Excel如何设置特定样式而不使用它们的名称?

\n\n

名称已本地化,因此对我的应用程序毫无用处,该应用程序将由不同语言的 Excel 版本使用。

\n\n

我能想到的一个丑陋的解决方案是保留应用于隐藏工作表上某些单元格的样式列表,然后检查它们的名称并在运行时使用它们......

\n\n

但一定有更简单的方法,对吗?MS 不可能搞砸 Excel 如此重要的方面。

\n\n

PS 以下是注册宏的一些示例样式:

\n\n
Selection.Style = "Akcent 6"\nRange("G4").Select\nSelection.Style = "60% \xe2\x80\x94 akcent 6"\nRange("G5").Select\nSelection.Style = "Akcent 5"\n
Run Code Online (Sandbox Code Playgroud)\n

Gar*_*ent 4

为了在您分发的工作簿中建立样式,您可以创建自己的样式并为其指定名称。例如przemo1przemo2等。

例如:

Sub MakeAStyle()
    ActiveWorkbook.Styles.Add Name:="PrZemo1"
    With ActiveWorkbook.Styles("PrZemo1")
        .IncludeNumber = True
        .IncludeFont = True
        .IncludeAlignment = True
        .IncludeBorder = True
        .IncludePatterns = True
        .IncludeProtection = True
    End With
    With ActiveWorkbook.Styles("PrZemo1").Font
        .Name = "Arial Narrow"
        .Size = 11
        .Bold = False
        .Italic = False
        .Underline = xlUnderlineStyleNone
        .Strikethrough = False
        .Color = -16776961
        .TintAndShade = 0
        .ThemeFont = xlThemeFontNone
    End With
    With ActiveWorkbook.Styles("PrZemo1")
        .HorizontalAlignment = xlCenterAcrossSelection
        .VerticalAlignment = xlCenter
        .ReadingOrder = xlContext
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
    End With
End Sub
Run Code Online (Sandbox Code Playgroud)

编辑#1

以下是一些COLOR和相关索引:

颜色