我正在从工作表中的文本列表生成 XML,但我不知道如何检查当前单元格中是否有粗体字。我需要做的是检查 A 列中的每个单元格,将文本读入字符串,如果我点击任何粗体单词,请添加 周围有标签。
我知道您可以逐字符读取单元格内容,但不能读取其格式。
任何帮助将不胜感激!
您可以使用以下方法来检查单元格是否具有
- 粗体混合字符。在这种情况下它将返回
NULL
- 所有字符均为粗体。在这种情况下它将返回
TRUE
- 没有一个字符是粗体的。在这种情况下它将返回
FALSE
Example
Sub Sample()
Debug.Print Range("A1").Font.Bold
Debug.Print Range("A2").Font.Bold
Debug.Print Range("A3").Font.Bold
End Sub
要检查单元格是否有粗体字符,您也可以使用此函数(来自 VBA 或工作表)
'~~> This is an additional function which will return...
'~~> TRUE if Cell has mixed/all chars as bold
'~~> FALSE if cell doesn't have any character in bold.
'~~> This can also be used as a worksheet function.
Function FindBoldCharacters(ByVal aCell As Range) As Boolean
FindBoldCharacters = IsNull(aCell.Font.Bold)
If Not FindBoldCharacters Then FindBoldCharacters = aCell.Font.Bold
End Function
截屏
你可以使用.Characters().Font.FontStyle
检查每个字符是否为粗体。使用上面的范围A1
例子。
Sub Sample()
For i = 1 To Len(Range("A1").Value)
Debug.Print Range("A1").Characters(i, 1).Font.FontStyle
Next i
End Sub
截屏
修改代码
Sub Sample()
For i = 1 To Len(Range("A1").Value)
If Range("A1").Characters(i, 1).Font.FontStyle = "Bold" Then
Debug.Print "The " & i & " character is in bold."
End If
Next i
End Sub
截屏
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)