【发布时间】:2021-09-02 13:38:47
【问题描述】:
我正在遍历单元格,试图将单元格值的某些部分加粗。我有一个包含内容的单元格:
<b>This part should be bold</b> but this should not be
我可以将正确的部分加粗,但下一步是删除标签。以下行会导致问题:
Cells.Replace What:="<b>", Replacement:="", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Cells.Replace What:="</b>", Replacement:="", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
当这些行运行时(以任意顺序),整个单元格值变为粗体。更具体地说,在逐行运行之后,运行任何一行都会得到相同的结果。我是 VBA 新手,不确定是什么原因造成的。
我用来使子字符串加粗的函数是:
fCell.Characters(Start:=m, Length:=n - m + 1).Font.Bold = True
其中 fCell 被循环,m 和 n 分别是定位 和 的索引。
【问题讨论】:
标签: excel vba formatting format