交叉引用字体颜色设置(宏操作)
首先启用宏
ZoteroLinkCitation Zotero超链接
Public Sub ZoteroLinkCitation()
Dim nStart&, nEnd&
nStart = Selection.Start
nEnd = Selection.End
Application.ScreenUpdating = False
Dim title As String
Dim titleAnchor As String
Dim style As String
Dim fieldCode As String
Dim numOrYear As String
Dim pos&, n1&, n2&
ActiveWindow.View.ShowFieldCodes = True
Selection.Find.ClearFormatting
With Selection.Find
.Text = "^d ADDIN ZOTERO_BIBL"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="Zotero_Bibliography"
.DefaultSorting = wdSortByName
.ShowHidden = True
End With
ActiveWindow.View.ShowFieldCodes = False
For Each aField In ActiveDocument.Fields
If InStr(aField.Code, "ADDIN ZOTERO_ITEM") > 0 Then
fieldCode = aField.Code
pos = 0
Do While InStr(fieldCode, """title"":""") > 0
n1 = InStr(fieldCode, """title"":""") + Len("""title"":""")
n2 = InStr(Mid(fieldCode, n1, Len(fieldCode) - n1), """,""") - 1 + n1
title = Mid(fieldCode, n1, n2 - n1)
titleAnchor = Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(title, " ", "_"), "&", "_"), ":", "_"), ",", "_"), "-", "_"), ".", "_"), "(", "_"), ")", "_"), "?", "_"), "!", "_")
titleAnchor = Left(titleAnchor, 40)
Selection.GoTo What:=wdGoToBookmark, Name:="Zotero_Bibliography"
Selection.Find.ClearFormatting
With Selection.Find
.Text = Left(title, 255)
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Paragraphs(1).Range.Select
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:=titleAnchor
.DefaultSorting = wdSortByName
.ShowHidden = True
End With
aField.Select
Selection.Find.ClearFormatting
With Selection.Find
.Text = "^#"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=pos
Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
numOrYear = Selection.Range.Text & ""
pos = Len(numOrYear)
style = Selection.style
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:="", SubAddress:=titleAnchor, ScreenTip:="", TextToDisplay:="" & numOrYear
aField.Select
Selection.style = style
fieldCode = Mid(fieldCode, n2 + 1, Len(fieldCode) - n2 - 1)
Loop
End If
Next aField
ActiveDocument.Range(nStart, nEnd).Select
End Sub
改变Zotero参考文献数字编号颜色及格式化()
Sub 改变Zotero参考文献数字编号颜色及格式化()
ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.color = wdColorBlue
With Selection.Find
.Text = "^19 ADDIN ZOTERO_ITEM"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
End Sub
交叉引用图表、公式字体颜色
Sub CitingColor()
Dim field As field
Dim rng As Range
ActiveDocument.Fields.Update
For Each field In ActiveDocument.Fields
If field.Type = wdFieldRef Then
Set rng = field.Result
rng.Font.color = wdColorBlue
End If
Next field
End Sub
锁定字段
Sub LockFields()
Dim field As field
For Each field In ActiveDocument.Fields
field.Locked = True
Next field
End Sub