我有下面的VBA代码来定义一个名为AlreadyCompleted
的自定义样式。这表示该行中的项目已完成。
代码为:
Sub DefineAlreadyCompleted()
Dim wb As Workbook
Dim theNewStyle As Style
Set wb = ThisWorkbook
' Check to see if Style already exists
On Error Resume Next
Set theNewStyle = wb.Styles("AlreadyCompleted")
On Error GoTo 0
' If Style Already Exists, Do Nothing
If Not theNewStyle Is Nothing Then
Exit Sub
End If
' Add New Style
Set theNewStyle = wb.Styles.Add("AlreadyCompleted")
' Define the Formatting Properties
With theNewStyle
.IncludeNumber = True
.Font.Strikethrough = True
.Interior.Color = wb.Styles("Good").Interior.Color
End With
End Sub
有问题的表格有一些自定义数字格式。第一列包含“0-00000-00000”格式的mat的ID号,第5列和第6列包含“m/dd/yyyy”格式的日期。当应用此样式时,ID号将恢复为常规数字(0-12345-67890
变为1234567890
),日期将变为数字字符串(10/31/2025
变为45961
)。
有没有什么方法可以改变这个样式,以保留列中已经使用的相应数字格式,而不必编写一个子例程来返回并再次将其放回?
1条答案
按热度按时间zujrkrfu1#
就定了
而不是True以不包括数字格式。
通过Excel UI添加样式时,默认情况下启用所有设置: