我需要处理一个excel文件,其中输入了alpha符号(α)作为已应用符号字体的“a”字符。
导出文件时,格式化将丢失,并且α和a之间不再有区别。
是否可以使用VBA将具有符号格式的“a”替换为α符号?
答案 0 :(得分:1)
Public Sub ReplaceAlpha(ByVal Where As Range)
With Application.FindFormat
.Clear
.Font.Name = "Symbol"
End With
With Application.ReplaceFormat
.Clear
.Font.Name = "Arial"
End With
Where.Replace What:="a", Replacement:=ChrW$(&H251), LookAt:=xlPart, SearchFormat:=True, ReplaceFormat:=True
End Sub
虽然这不会找到格式不同的字符串中的字母 如果你有这些,你需要像
这样的东西Public Sub ReplaceAlpha(ByVal Where As Range)
Dim cur_cell As Range
For Each cur_cell In Where
Dim i As Long
For i = 1 To Len(cur_cell.Value)
With cur_cell.Characters(i, 1)
If .Text = "a" Then
If .Font.Name = "Symbol" Then
.Text = ChrW$(&H251)
.Font.Name = "Arial"
End If
End If
End With
Next
Next
End Sub