我正在尝试用常规字符替换重音字符。
当我尝试运行宏时,它没有出现在列表中。
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
最佳答案
block 引用> block 引用>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
请参阅上面代码中的注释。
block 引用> block 引用>'-- 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/