Excel 將金額轉換成大寫字母函式
Function CapsMoney(curMoney As Currency) As String '轉換中文大寫金額函式
Dim curMoney1 As Long
Dim i1 As Long '儲存整數部分(元部分)
Dim i2 As Integer '儲存十分位(角部分)
Dim i3 As Integer '儲存百分位(分部分)
Dim s1 As String, s2 As String, s3 As String '儲存轉換後的字串
curMoney1 = Round(curMoney * 100) '將金額擴大100倍,並進行四捨五入
i1 = Int(curMoney1 / 100) '獲取元部分
i2 = Int(curMoney1 / 10) - i1 * 10 '獲取角部分
i3 = curMoney1 - i1 * 100 - i2 * 10 '獲取分部分
s1 = Application.WorksheetFunction.Text(i1, "[dbnum2]")
'將元部分轉為中文大寫
s2 = Application.WorksheetFunction.Text(i2, "[dbnum2]")
'將角部分轉為中文大寫
s3 = Application.WorksheetFunction.Text(i3, "[dbnum2]")
'將分部分轉為中文大寫
s1 = s1 & "元" '整數部分
If i3 <> 0 And i2 <> 0 Then '分和角都不為0
s1 = s1 & s2 & "角" & s3 & "分"
If i1 = 0 Then '元部分為0
s1 = s2 & "角" & s3 & "分"
End If
End If
If i3 = 0 And i2 <> 0 Then '分為0,角不為0
s1 = s1 & s2 & "角整"
If i1 = 0 Then '元部分為0
s1 = s2 & "角整"
End If
End If
If i3 <> 0 And i2 = 0 Then '分不為0,角為0
s1 = s1 & s2 & s3 & "分"
If i1 = 0 Then '元為0
s1 = s3 & "分"
End If
End If
If Right(s1, 1) = "元" Then s1 = s1 & "整" '為"元"後加上一個"整"字
CapsMoney = s1
End Function