外貌像你的風格「Body Text,bt」是純粹的段落風格。這意味着它只適用於一個完整的段落。
但是,在您的屏幕截圖中,僅選擇了第二段的一部分。確保選擇了完整的段落,或者如果該樣式只應用於段落的一部分,則將樣式「Body Text,bt」設置爲鏈接(段落和字符)樣式。
對不連續選擇的編程訪問非常有限,只能使用Word UI創建此類選擇。 MSDN文章Limited programmatic access to Word discontiguous selections給出了一些更多細節。
如果應用樣式只到款的一部分(通過使鏈接的風格)是不是你想要的,你可能要拿出這樣一個黑客:
Sub BodyTextApply()
Dim oRange As Range
' create a temporary character style
ActiveDocument.Styles.Add "_TEMP_STYLE_", wdStyleTypeCharacter
' apply the temporary style to the discontiguous selection
Selection.Style = ActiveDocument.Styles("_TEMP_STYLE_")
Set oRange = ActiveDocument.Range
With oRange.Find
.ClearAllFuzzyOptions
.ClearFormatting
.ClearHitHighlight
.Style = ActiveDocument.Styles("_TEMP_STYLE_")
.Text = ""
.Wrap = wdFindStop
' search for all occurences of the temporary style and format the
' complete paraphraph with the desired style
Do While .Execute
oRange.Paragraphs(1).Style = ActiveDocument.Styles("Body Text,bt")
Loop
End With
' cleanup
ActiveDocument.Styles("_TEMP_STYLE_").Delete
End Sub
你可能想添加一些錯誤處理,以確保使用的臨時樣式最終從文檔中刪除。
在Word 2007中對我有用嗎? – RBarryYoung 2009-08-16 18:10:01