问题描述
我在Excel中使用以下功能或VBA将数字转换为字母。 此代码在Excel中效果很好。
Global AlphaNumeric1(0 To 19) As String
Global AlphaNumeric2(1 To 9) As String
Global AlphaNumeric3(1 To 9) As String
Sub alphaset()
Dim i%
AlphaNumeric1(0) = "Zero"
AlphaNumeric1(1) = "One"
.
.
.
AlphaNumeric1(19) = "Nineteen"
AlphaNumeric2(1) = "Ten "
.
.
.
AlphaNumeric2(9) = "Ninety "
AlphaNumeric3(1) = "One hundred"
.
.
.
AlphaNumeric3(9) = "nine hundred"
End Sub
Function Digit2Word(Number As String) As String
alphaset
Dim No As Currency,N As String
On Error GoTo Digit2Worderror
No = CCur(Number)
N = CStr(No)
Select Case Len(N)
Case 1 To 3:
If N < 20 Then
Digit2Word= AlphaNumeric1(N)
ElseIf N < 100 Then
If N Mod 10 = 0 Then
Digit2Word= AlphaNumeric2(N \ 10)
Else
Digit2Word= AlphaNumeric2(N \ 10) & " and " & Digit2Word(N Mod 10)
End If
ElseIf N < 1000 Then
If N Mod 100 = 0 Then
Digit2Word= AlphaNumeric3(N \ 100)
Else
Digit2Word= AlphaNumeric3(N \ 100) & " and " & Digit2Word(N Mod 100)
End If
End If
Case 4 To 6:
If (Right(N,3)) = 0 Then
Digit2Word= Digit2Word(Left(N,Len(N) - 3)) & " Thousand "
Else
Digit2Word= Digit2Word(Left(N,Len(N) - 3)) & " Thousand and " & Digit2Word(Right(N,3))
End If
Case 7 To 9:
If (Right(N,6)) = 0 Then
Digit2Word= Digit2Word(Left(N,Len(N) - 6)) & " Million "
Else
Digit2Word= Digit2Word(Left(N,Len(N) - 6)) & " Million and " & Digit2Word(Right(N,6))
End If
Case Else:
If (Right(N,9)) = 0 Then
Digit2Word= Digit2Word(Left(N,Len(N) - 9)) & " Billion "
Else
Digit2Word= Digit2Word(Left(N,Len(N) - 9)) & " Billion and " & Digit2Word(Right(N,9))
End If
End Select
Exit Function
Digit2Worderror:
Digit2Word= "#Error"
End Function
如何通过运行Macro将该VBA转换为在Word中使用? (例如,选择鼠标指针打开的数字并将其转换为字母。在Word中运行宏,而无需链接到Excel)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)