|
本帖最后由 sbww8800 于 2017-6-20 07:54 编辑
word中,选中一串字符,为选中的每个字符加上方框,求代码,望帮忙。。。
拜读守柔老师的帖,修改一条语句就行。。。
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 = Selection.Range '所选字符 这是修改的语句
' 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 = 12 '字体大小
.Fields.Update '更新域
Next
End With
Application.ScreenUpdating = True '恢复屏幕更新
End Sub
|
|