我正在处理一些Excel文件,这些文件通常在单元格中有很多文本.我想运行检查以确保所有文本都是相同的字体(特别是Calibri).
目前,我有这样做的方式.但它运行得非常慢.
Function fnCalibriCheck() As String
Dim CurrentCell As Range ' The current cell that is being checked
Dim SelectedRng As Range ' The selection range
Dim F As Long
Set SelectedRng = ActiveSheet.Range(Selection.Address) ' Defines the selection range
For Each CurrentCell In SelectedRng ' Goes through every cell in the selection and performs the check
For F = 1 To Len(CurrentCell)
If CurrentCell.Characters(F, 1).font.Name <> "Calibri" Then
fnCalibriCheck = "not calibri"
End If
Next
Next
End Function
Run Code Online (Sandbox Code Playgroud)
问题似乎是Font.Name属性特有的.例如,如果我运行相同的代码,但我搜索特定字符而不是Font.Name,那么它运行完全正常.虽然如此,我当前的宏可能需要几秒钟才能运行,偶尔会崩溃.
我想知道是否有人可以提出更好的选择.