1

我正在尝试格式化给定的范围。下面代码中一个类的 BorderStyle 属性的值是“xlMedium”,它是字符串数据类型,但是权重属性需要 xlMedium 作为常量,我如何将这个字符串值转换为常量?

谢谢你。

Function applyFormat(ByRef objRng As clsRange)

 ' Select the Range

     Worksheets(objRng.SheetName).Select

     Worksheets(objRng.SheetName).Range(objRng.RangeValue).Select

            With Selection.Borders(xlInsideVertical)
                 .LineStyle = xlContinuous
                 .ColorIndex = 0
                 .TintAndShade = 0
                 .Weight = (Me.BorderStyle)
            End With

            With Selection.Borders(xlInsideHorizontal)
                 .LineStyle = xlContinuous
                 .ColorIndex = 0
                 .TintAndShade = 0
                 .Weight = (Me.BorderStyle)
            End With

End Function
4

1 回答 1

2

没有简单的方法可以将字符串转换为其等效的枚举成员。

您应该更改BorderStyle as XlBorderWeight并使用显式整数值,如果您不这样做,则需要手动查找每个成员;

public property get BorderStyleValue() as XlBorderWeight   
   select case Me.BorderWeight 
      case "xlMedium": BorderStyleValue= XlBorderWeight.xlMedium
      case "xlThick" : BorderStyleValue= XlBorderWeight.xlThick
      ...

...

.weight = Me.BorderStyleValue
于 2012-08-09T11:10:11.057 回答