'======================函数1======================Sub UpdateFiledStyle() '更新某个域所在行的格式,用于更新表或者图的标题极度有用Dim aFeild As FieldsDim str As StringFor Each aField In ActiveDocument.Fieldsstr = 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.SelectSelection.EndKey Unit:=wdLineSelection.HomeKey Unit:=wdLine, Extend:=wdExtendSelection.Style = ActiveDocument.Styles("图标题")End If Next aFieldEnd Sub'======================函数3======================Sub UpdateFiledStyleLine() '去掉标题和域数字之间的空格Dim aFeild As FieldsDim str As String'Dim str2 As StringDim i As Integeri = 1For 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 StringstrHead = Selection.TextSelection.Text = Replace(strHead, " ", "")End If Next aFieldEnd Sub'======================函数4======================Sub UpdateFiledStyleLine2() '去掉域数字和表名之间的多余空格'Call UpdateFiledStyleLineDim aFeild As FieldsDim str As StringFor 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.SelectDim strTail As StringSelection.MoveRight Unit:=wdCharacter, Count:=1Selection.EndKey Unit:=wdLine, Extend:=wdExtend '选中域后面所有文本Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtendstrTail = Selection.TextSelection.Text = " " & Replace(strTail, " ", "")End IfNext aFieldEnd Sub