Zotero Word中插入带超链接的参考文献

文章介绍了如何在MicrosoftWord中使用Zotero插件处理超链接,包括Citation功能的实现,以及如何修改超链接颜色和为DOI添加超链接。作者分享了遇到的问题和解决方法,展示了相关代码片段和调整过程。
摘要由CSDN通过智能技术生成

Zotero 超链接

找了好多原代码,最接近能实施的为:
https://blog.csdn.net/weixin_47244593/article/details/129072589
但是,就是向他说的一样会报错,我修改了代码,遇见报错的地方会直接跳过不执行,事后找出自己再单独添加较为特殊文章即可,代码如下:

Public Sub ZoteroLinkCitation()
    On Error Resume Next ' Add this line to enable error handling
    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

超链接颜色变化

在这里也给出全盘改变超链接颜色的代码:
参考链接如下:https://zhuanlan.zhihu.com/p/680291144

Sub CitingColor()
    For i = 1 To ActiveDocument.Fields.Count '遍历文档所有域
        ' Word 自带的交叉引用的域代码起始 4 位是 " REF" (注意空格)
        ' Endnote 插入的引用域代码的起始 14 位是 " ADDIN EN.CITE"
        ' Zotero 插入的引用域代码的起始 31 位是 " ADDIN ZOTERO_ITEM CSL_CITATION",可根据需求添加其他类型
        If Left(ActiveDocument.Fields(i).Code, 4) = " REF" Or Left(ActiveDocument.Fields(i).Code, 14) = " ADDIN EN.CITE" Or Left(ActiveDocument.Fields(i).Code, 31) = " ADDIN ZOTERO_ITEM CSL_CITATION" Then
        ActiveDocument.Fields(i).Select ' 选中上述几类域
        Selection.Font.Color = wdColorBlue ' 设置字体颜色为蓝色,可改为其他颜色,如 RGB(255,0,0)
        End If
    Next
End Sub

给doi插入超链接

参考链接

Sub AddHyperlinksToDOIs()
    Dim doc As Document
    Dim rng As Range
    Dim field As field
    Dim doi As String
    Dim test As String
    Set doc = ActiveDocument
    Set rng = doc.Range
    
    With rng.Find
        .ClearFormatting
        .Text = "doi:*^13"
        .MatchWildcards = True
        .Wrap = wdFindStop
        .Forward = True
        
        Do While .Execute
            rng.MoveEnd wdCharacter, -1
            doi = rng.Text
            doi = Mid(doi, 6, Len(doi) - 6)
            rng.Hyperlinks.Add Anchor:=rng, Address:="https://doi.org/" & doi
            ' 移动到下一个匹配项
            rng.Collapse wdCollapseEnd
            rng.MoveStart wdCharacter, 1
        Loop
        
    End With
End Sub
  • 6
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
Word插入参考文献超链接的方法如下: 1. 将光标定位在正文需要插入参考文献上标的地方。 2. 点击“插入”选项卡的“交叉引用”按钮。 3. 在弹出的窗口,选择“引用类型”为“编号项”。 4. 勾选“插入超链接”选项。 5. 选择需要插入参考文献,例如第一个参考文献。 6. 点击插入按钮,然后关闭“交叉引用”窗口。 7. 随后可见,正文已经插入了相应的编号,例如\[1\]。 8. 鼠标放在该编号上方会出现“按住Ctrl并单击可访问链接”的提示,说明该编号已经链接至正文后面的参考文献。 9. 如果需要将编号转换为上标,可以选编号,然后按下“Ctrl+Shift+=”即可将其转换为上标。 请注意,以上方法适用于Word参考文献超链接。 #### 引用[.reference_title] - *1* *3* [Word上标超链接参考文献](https://blog.csdn.net/weixin_36302584/article/details/117405594)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Zotero-word引用跳转到参考文献/建立超链接-引用格式(Xie et al 2021, Achanta et al 2012)](https://blog.csdn.net/weixin_47244593/article/details/129072589)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

暗中讨饭的卫3

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值