|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 xrs08234 于 2012-5-11 14:44 编辑
以下代码是右键菜单实现小写金额转为大写金额,求高人帮我封装成Excel的右键菜单,谢谢!!!!!
Private Sub Workbook_Open()
Application.CommandBars("Cell").Reset
'添加一级菜单
Set 一级菜单 = Application.CommandBars("Cell").Controls.Add(Type:=msoControlPopup, Before:=1) '取消参数before,新建菜单排列在原菜单的末尾
一级菜单.Caption = "金额大写"
'添加二级菜单
Set 二级菜单 = 一级菜单.Controls.Add(Type:=msoControlButton)
With 二级菜单
.Caption = "小写转换大写"
.Style = msoButtonCaption
.OnAction = "大写金额工具"
End With
End Sub
Sub 大写金额工具()
If ActiveCell = "" Then Exit Sub
If IsNumeric(ActiveCell) Then
ActiveCell = dx(ActiveCell)
End If
End Sub
Function dx(q)
ybb = Round(q * 100) '将输入的数值扩大100倍,进行四舍五入
y = Int(ybb / 100) '截取出整数部分
j = Int(ybb / 10) - y * 10 '截取出十分位
f = ybb - y * 100 - j * 10 '截取出百分位
zy = Application.WorksheetFunction.Text(y, "[DBNum2]") '将整数部分转为中文大写
zj = Application.WorksheetFunction.Text(j, "[DBNum2]") '将十分位转为中文大写
zf = Application.WorksheetFunction.Text(f, "[DBNum2]") '将百分位转为中文大写
dx = "大写(人民币):" & zy & "圆" & "整"
d1 = "大写(人民币):" & zy & "圆"
If f <> 0 And j <> 0 Then
dx = d1 & zj & "角" & zf & "分"
If y = 0 Then
dx = "大写(人民币):" & zj & "角" & zf & "分"
End If
End If
If f = 0 And j <> 0 Then
dx = d1 & zj & "角" & "整"
If y = 0 Then
dx = "大写(人民币):" & zj & "角" & "整"
End If
End If
If f <> 0 And j = 0 Then
dx = d1 & zj & zf & "分"
If y = 0 Then
dx = "大写(人民币):" & zf & "分"
End If
End If
If q = 0 Or q = "" Then
dx = "大写(人民币):零圆整" '如没有输入任何数值为0
End If
End Function
|
|