excel - 如何调用未出现在列表中的宏,将重音字符转换为常规字符?

标签 excel vba

我正在尝试用常规字符替换重音字符。

当我尝试运行宏时,它没有出现在列表中。

Option Explicit

'-- Add more chars to these 2 string as you want
'-- You may have problem with unicode chars that has code > 255
'-- such as some Vietnamese characters that are outside of ASCII code (0-255)
Const AccChars = "ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðñòóôõöùúûüýÿ"
Const RegChars = "SZszYAAAAAACEEEEIIIIDNOOOOOUUUUYaaaaaaceeeeiiiidnooooouuuuyy"

Sub StripAccent(aRange As Range)
'-- Usage: StripAccent Sheet1.Range("A1:C20")
Dim A As String * 1
Dim B As String * 1
Dim i As Integer

For i = 1 To Len(AccChars)
A = Mid(AccChars, i, 1)
B = Mid(RegChars, i, 1)
aRange.Replace What:=A, _
Replacement:=B, _
LookAt:=xlPart, _
MatchCase:=True
Next

End Sub

最佳答案

I do not see the option to run the macro in my macros list. The macro name is not appearing in the list to select. I have macros enabled and I have a bunch of others I use so I do not understand why it's not showing. – BvilleBullet 4 mins ago

请参阅上面代码中的注释。

'-- Usage: StripAccent Sheet1.Range("A1:C20")

你必须这样调用它

Option Explicit

'-- Add more chars to these 2 string as you want
'-- You may have problem with unicode chars that has code > 255
'-- such as some Vietnamese characters that are outside of ASCII code (0-255)
Const AccChars = "ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðñòóôõöùúûüýÿ"
Const RegChars = "SZszYAAAAAACEEEEIIIIDNOOOOOUUUUYaaaaaaceeeeiiiidnooooouuuuyy"

'~~> This is how you have to call it. Now You can see the macro "Sample" in the list
Sub Sample()
    StripAccent Sheet1.Range("A1:C20")
End Sub

Sub StripAccent(aRange As Range)
    '-- Usage: StripAccent Sheet1.Range("A1:C20")
    Dim A As String * 1
    Dim B As String * 1
    Dim i As Integer

    For i = 1 To Len(AccChars)
        A = Mid(AccChars, i, 1)
        B = Mid(RegChars, i, 1)
        aRange.Replace What:=A, _
        Replacement:=B, _
        LookAt:=xlPart, _
        MatchCase:=True
    Next
End Sub

关于excel - 如何调用未出现在列表中的宏,将重音字符转换为常规字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10032322/

相关文章:

vba - 列出 Excel 工作表和图表选项卡

vba - 将变量传递给 button_click 过程

excel - 慢查找宏

c# - 图表的 SetSourceData 返回数据透视表的 HRESULT E_FAIL (Excel C#)

excel - 放置在工作表 1 中的 VBA 宏按钮可在隐藏的工作表 2 中运行宏

excel - 难以在 VBA Excel 中找到行尾

excel - 无法在 VBA 中使用 "wininet.dll"连接到 FTP 服务器,但可以使用 WinSCP 连接

c# - ASP.NET MVC Excel 导出文件格式错误

python - 通过 Pandas 和 Numpy.ndarray 类型将 Excel 矩阵转换为 JSON

excel - 如何在没有工作表名称的情况下为 Excel 图表引用当前工作表数据