'======================函数1====================== Sub UpdateFiledStyle() '更新某个域所在行的格式,用于更新表或者图的标题极度有用 Dim aFeild As Fields Dim str As String For Each aField In ActiveDocument.Fields str = aField.Code.Text '直接取字符串,他的前后有个看不到的字符串,必须去掉才能比较 str = Left(str, Len(str) - 1) str = Right(str, Len(str) - 1) If (str = "SEQ 图 * ARABIC") Then 'MsgBox ("找到域") '找到域的位置后,相当于光标定位到行,按End键,光标到最后,在Ctrl+Home,全选此行,再更改样式 aField.Select Selection.EndKey Unit:=wdLine Selection.HomeKey Unit:=wdLine, Extend:=wdExtend Selection.Style = ActiveDocument.Styles("图标题") End If Next aField End Sub '======================函数3====================== Sub UpdateFiledStyleLine() '去掉标题和域数字之间的空格 Dim aFeild As Fields Dim str As String 'Dim str2 As String Dim i As Integer i = 1 For Each aField In ActiveDocument.Fields '.Item(0). str = aField.Code.Text '直接取字符串,他的前后有个看不到的字符串,必须去掉才能比较 str = Left(str, Len(str) - 1) str = Right(str, Len(str) - 1) If (str = "SEQ 图 * ARABIC") Then 'MsgBox ("找到域") '选中域所在行,到首行,光标左移,选中前面所有文本,去掉空格 aField.Select Selection.MoveLeft Unit:=wdCharacter, Count:=1 Selection.HomeKey Unit:=wdLine, Extend:=wdExtend Dim strHead As String strHead = Selection.Text Selection.Text = Replace(strHead, " ", "") End If Next aField End Sub '======================函数4====================== Sub UpdateFiledStyleLine2() '去掉域数字和表名之间的多余空格 'Call UpdateFiledStyleLine Dim aFeild As Fields Dim str As String For Each aField In ActiveDocument.Fields '.Item(0). str = aField.Code.Text '直接取字符串,他的前后有个看不到的字符串,必须去掉才能比较 str = Left(str, Len(str) - 1) str = Right(str, Len(str) - 1) If (str = "SEQ 图 * ARABIC") Then 'MsgBox ("找到域") '找到域的位置后,选中域,右移一个字符,将后面的全选,然后去掉所有空格,再在前面加一个空格 aField.Select Dim strTail As String Selection.MoveRight Unit:=wdCharacter, Count:=1 Selection.EndKey Unit:=wdLine, Extend:=wdExtend '选中域后面所有文本 Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend strTail = Selection.Text Selection.Text = " " & Replace(strTail, " ", "") End If Next aField End Sub