Dra*_*ake 41 microsoft-office microsoft-word-2007 microsoft-word
没什么可补充的,我想立即更改Word 2007 文档中所有交叉引用的样式。但我不知道该怎么做。如何才能做到这一点?
Den*_*son 46
一些交叉引用类型会自动设置为“强烈引用”样式,但大多数会被设置为“普通”文本格式。
要将“强烈引用”样式应用于交叉引用的文本:
要更改给定样式的所有文本的外观:
要一次将样式应用于所有交叉引用:
^19 REF
有关查找和替换中特殊代码的更多信息,请参阅此页面。
这是一个将开关添加\* mergeformat
到每个字段的宏。如果您进行字段更新,此开关对于防止格式丢失是必要的。您可以将宏分配给一次击键,并且每次您按下击键时,它都会一次遍历一个字段。您还可以编辑宏以遍历整个文档以自动执行此过程。
Sub mf()
'
' mf Macro
' Find cross references and add \* mergeformat
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = "^19 REF"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="\* mergeformat "
Selection.Find.Execute
End Sub
Run Code Online (Sandbox Code Playgroud)
小智 6
使用以下宏将 CHARFORMAT 添加到所有交叉引用。仅当字符串不存在时,此宏才会将字符串添加到字段中。
Sub SetCHARFORMAT()
'
' Set CHARFORMAT switch to all {REF} fields. Replace MERGEFORMAT.
'
'
Dim oField As Field
Dim oRng As Range
For Each oField In ActiveDocument.Fields
'For Each oField In Selection.Fields
If InStr(1, oField.Code, "REF ") = 2 Then
If InStr(1, oField.Code, "MERGEFORMAT") <> 0 Then
oField.Code.Text = Replace(oField.Code.Text, "MERGEFORMAT", "CHARFORMAT")
End If
If InStr(1, oField.Code, "CHARFORMAT") = 0 Then
oField.Code.Text = oField.Code.Text + "\* CHARFORMAT "
End If
End If
Next oField
End Sub
Run Code Online (Sandbox Code Playgroud)使用这个宏来格式化所有带有“微妙引用”样式的交叉引用(确保你有这样的样式,并显示域代码):
Sub SetCrossRefStyle()
'
' Macro to set styole of all cross references to "Subtle Reference"
'
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles( _
"Subtle Reference")
With Selection.Find
.Text = "^19 REF"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchKashida = False
.MatchDiacritics = False
.MatchAlefHamza = False
.MatchControl = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Run Code Online (Sandbox Code Playgroud)按Alt+F9隐藏域代码