以下是引用zhang5156在2008-7-18 14:17:24的发言:版主好,我是在正常的文件操作界面下录入。我想实现在……后面只要我录入数字,就能自动为它加方框,比如我敲入数字1,就自动为它填加方框内有1的格式。请老师为我编个VBA应用域,我试了几次没编明白,见笑了。 以下代码供参考: '* +++++++++++++++++++++++++++++ '* Created By SHOUROU@ExcelHome 2008-7-19 14:43:09 '仅测试于System: Windows NT Word: 11.0 Language: 2052 '№ 0417^The Code CopyIn [ThisDocument-ThisDocument]^' '* ----------------------------- Option Explicit Sub SetNumberBorder() Const myEQ As String = "EQ \X(" Dim myString As String Dim strTemp As String Dim bytLenth As Byte Dim i As Byte Dim oChar As String * 1 Dim LastRange As Range Dim NewField As Field myString = InputBox("请输入您的目标数字!") bytLenth = Len(myString) If bytLenth = 0 Then Exit Sub Application.ScreenUpdating = False '关闭屏幕更新 If Selection.Type <> wdSelectionIP Then Selection.Delete '总是删除所选内容 With ActiveDocument For i = 1 To bytLenth '建立一个循环 oChar = Mid(myString, i, 1) Set LastRange = Selection.Range Set NewField = .Fields.Add(LastRange, wdFieldEmpty, myEQ & oChar & ")", False) strTemp = NewField.Code.Text '获得域代码 strTemp = VBA.RTrim(strTemp) '去除域代码的右侧空格 NewField.Code.Text = strTemp '重写域代码 NewField.Code.Font.Name = "Arial" '设置域代码的字体 NewField.Code.Font.Size = 10 '字体大小 .Fields.Update '更新域 Next End With Application.ScreenUpdating = True '恢复屏幕更新 End Sub '---------------------- 请单击常用工具栏中的第一个按钮(数字自动边框)
kqNuQDia.rar
(12.23 KB, 下载次数: 116)
|