交叉引用字体颜色设置(宏操作)

交叉引用字体颜色设置(宏操作)

首先启用宏在这里插入图片描述

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
' check if the field is a Zotero in-text reference
    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
            'Selection.style = ActiveDocument.Styles("CitationFormating")
            
            fieldCode = Mid(fieldCode, n2 + 1, Len(fieldCode) - n2 - 1)
        
        Loop
    End If
Next aField
ActiveDocument.Range(nStart, nEnd).Select
End Sub

改变Zotero参考文献数字编号颜色及格式化()

Sub 改变Zotero参考文献数字编号颜色及格式化()
' 改变Zotero参考文献数字编号颜色及格式化 宏

' 切换显示字段代码
ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes

' 清除查找和替换格式设置
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting

' 设置查找替换的字体颜色为12611584(对应16进制蓝色颜色值,也可用“wdColorBlue”替换)
Selection.Find.Replacement.Font.color = wdColorBlue

' 使用Selection.Find对象设置查找参数
With Selection.Find
    .Text = "^19 ADDIN ZOTERO_ITEM" ' 查找的内容是"^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 ' wdFieldRef 代表交叉引用类型
            Set rng = field.Result
            ' 将交叉引用的字体颜色设置为蓝色
            rng.Font.color = wdColorBlue ' 修改为正确的 Font.Color
        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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值