VBA-转换“;xlMedium“;到恒定XLM介质
我正在尝试设置给定范围的格式。下面代码中类的BorderStyle属性的值为“xlMedium”,该值为字符串数据类型,但weight属性需要xlMedium作为常量,如何将该字符串值转换为常量 多谢各位VBA-转换“;xlMedium“;到恒定XLM介质,vba,excel,Vba,Excel,我正在尝试设置给定范围的格式。下面代码中类的BorderStyle属性的值为“xlMedium”,该值为字符串数据类型,但weight属性需要xlMedium作为常量,如何将该字符串值转换为常量 多谢各位 Function applyFormat(ByRef objRng As clsRange) ' Select the Range Worksheets(objRng.SheetName).Select Worksheets(objRng.SheetName).Ra
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
没有简单的方法可以将字符串转换为等效的枚举成员 您应该更改为
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
谢谢Alex,我想知道我们是否可以以某种方式使用Evaluate函数,我不知道具体如何使用。内置的.Evaluate仅用于工作表函数,存在这个怪物;或者你可以通过依赖typelib信息库,或者引用脚本控件来实现,但是这样做是非常讨厌的