| 发表于:2007-08-14 10:18:3111楼 得分:100 |
以获取第一行金额为例,代码如下 sub 获取金额示例() ' ' 获取金额示例 macro ' 宏在 2007-8-14 由 kmlxk@yahoo.com.cn 录制 ' dim smoney as string dim sbit as string dim i as long dim x as long, y as long smoney = space(12) '长度为12的字符串,储存金额 mid(smoney, 10, 1) = ". " '小数点 activedocument.bookmarks( "ki011 ").select '选择书签 selection.selectcell '选择书签所在单元格 mid(smoney, 12, 1) = left(selection.text, 1) '保存书签指向的 '分 ' '获取单元格 行列 x = selection.cells(1).columnindex - 1 '前一单元格 y = selection.cells(1).rowindex selection.tables(1).cell(y, x).select '选择前一单元格 '角 ' mid(smoney, 11, 1) = left(selection.text, 1) '保存 '循环选择整数部分 for i = 1 to 9 selection.tables(1).cell(y, x - i).select sbit = left(selection.text, 1) if isnumeric(sbit) then '如果单元格中填有数字 mid(smoney, 10 - i, 1) = sbit '保存 end if next msgbox smoney '最后金额 end sub sub 金额拆分示例() '金额限制条件 '最大: 亿 小数: 两位 ' ' 金额拆分示例 macro ' 宏在 2007-8-10 由 kmlxk@yahoo.com.cn 录制 ' dim mynewtable as table dim i as long, j as long dim smoney as string dim dmoney as double dim lmoney100 '新建5行13列的表 set mynewtable = activedocument.tables.add(range:=selection.range, numrows:=5, numcolumns:= _ 13, defaulttablebehavior:=wdword9tablebehavior, autofitbehavior:= _ wdautofitfixed) with mynewtable '填充表头 .cell(1, 1).select: selection.text = "项目 " .cell(1, 2).select: selection.text = "金额 " .cell(1, 3).select: selection.text = "亿 " .cell(1, 4).select: selection.text = "千 " .cell(1, 5).select: selection.text = "百 " .cell(1, 6).select: selection.text = "十 " .cell(1, 7).select: selection.text = "万 " .cell(1, 8).select: selection.text = "千 " .cell(1, 9).select: selection.text = "百 " .cell(1, 10).select: selection.text = "十 " .cell(1, 11).select: selection.text = "元 " .cell(1, 12).select: selection.text = "角 " .cell(1, 13).select: selection.text = "分 " '填充金额 .cell(2, 2).select: selection.text = "49645.3 " .cell(3, 2).select: selection.text = "697395.32 " .cell(4, 2).select: selection.text = "786.80 " .cell(5, 2).select: selection.text = "289712351.51 " '循环每行 for i = 2 to 5 .cell(i, 2).select dmoney = val(selection.text) '取得金额 lmoney100 = dmoney * 100 '金额扩大100倍,去除小数点 smoney = right(string(12, " ") & cstr(lmoney100), 11) '金额前填充12个0,然后截取后面11位 for j = 1 to len(smoney) '循环每一位填充到表格中 .cell(i, j + 2).select selection.text = mid(smoney, j, 1) next next end with end sub | | |
|