'======================函數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