我有一个字体来显示特定的符号。它们使用标准/默认字体键入工作表。我能够识别这些字符,然后更改这些字符'字体到我的符号字体,但如果单元格中有多个已识别的符号,则无法使其正常工作。
例如,单元格可能包含:
此值为X和Y,Z
我需要更改X,Y和Z的字体。
以下是我目前正在改变角色的方式。字体来自vba:
Sub InsertFont(insertRange As Range, symbolText As String, symbolPosition As Integer)
Dim cellText As String
Dim newValue As String
cellText = insertRange.Value2
newValue = Replace(cellText, symbolText, SymbolDict.Item(symbolText), 1, 1)
insertRange.Value2 = newValue
With insertRange.Characters(symbolPosition, Len(SymbolDict.Item(symbolText))).Font
.Name = "MyFont"
End With
End Sub
问题是每次更改字体后,单元格的其余部分都会返回默认字体!如何才能更改字体以适应所有更改?
最终结果:
此值为X和Y,☹
答案 0 :(得分:0)
Sub InsertSymbol(insertRange As Range, symbolText As String, symbolPosition As Integer)
Dim cellText As String
Dim newValue As String
insertRange.Characters(symbolPosition, Len(symbolText)).Delete
insertRange.Characters(symbolPosition, 0).Insert SymbolDict.Item(symbolText) '2nd parameter 0 to not overwrite any characters
insertRange.Characters(symbolPosition, 1).Font.Name = "My Symbol Font Name"
End Sub