1

我需要处理一个 excel 文件,其中已将字母符号(α)作为已应用符号字体的“a”字符输入。

导出文件时,格式丢失,α 和 a 之间不再有区别。

是否可以使用 VBA 将具有符号格式的“a”替换为 α 符号?

4

1 回答 1

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
于 2012-12-03T10:40:39.650 回答