Skip to content

Commit

Permalink
add broken reference checking feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
shishouyuan committed May 20, 2021
1 parent 9fdb868 commit f8aa962
Show file tree
Hide file tree
Showing 17 changed files with 119 additions and 21 deletions.
Binary file removed Docs/HandyRef Introduction.docx
Binary file not shown.
Binary file added Docs/HandyRef User Guide.docx
Binary file not shown.
Binary file modified Docs/images/en/1-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Docs/images/en/2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Docs/images/zh/1-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Docs/images/zh/2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Docs/“HandyRef-快引”指南.docx
Binary file not shown.
102 changes: 95 additions & 7 deletions HandyRef.bas
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@
'步骤2:选中想要插入交插引用的地方然后执行宏 InsertCrossReferenceField。


Const HandyRefVersion = "20210520.0940"
Const HandyRefVersion = "20210520.1434"

Const TEXT_HandyRefGithubUrl = "https://github.com/shishouyuan/HandyRefVBA"



#Const HandyRef_Lang = "zh-cn"
Const BookmarkPrefix = "_HandyRef"
Const RefBrokenCommentTitle = "$HANDYREF_REFERENCE_BROKEN_COMMENT$"

#Const HandyRef_Lang = "en-us"

Const BrokenRefNumPosHolder = "#" '数量占位符
#If HandyRef_Lang = "zh-cn" Then

Const TEXT_HandyRefAppName = "HandyRef-快引"
Expand All @@ -36,21 +40,29 @@ Const TEXT_HandyRefGithubUrl = "https://github.com/shishouyuan/HandyRefVBA"
Const TEXT_InsertCrossReferenceField_CannotCrossFile = "不支持跨文件引用!"
Const TEXT_VersionPrompt = "版本:"
Const TEXT_NonCommecialPrompt = "仅限非商业用途"
Const TEXT_RefBrokenComment = "引用源丢失!"
Const TEXT_BrokenRefFoundPrompt = "发现了 " & BrokenRefNumPosHolder & " 个损坏的引用,已为其添加批注。"
Const TEXT_NoBrokenRefFoundPrompt = "没有发现损坏的索引。"
Const TEXT_RefBrokenCommentClearedPrompt = "引用损坏批注已清除。"

#Else

Const TEXT_HandyRefAppName = "HandyRef"
Const TEXT_HandyRefAuthor = "Shouyuan Shi @ South China University of Technology"
Const TEXT_HandyRefDescription = "Provide a handy way to insert Cross Reference in MS Word."
Const TEXT_CreateReferencePoint_NothingSelected = "Nothing Selected!"
Const TEXT_InsertCrossReferenceField_NoRefPoint = "No Reference Point selected!"
Const TEXT_InsertCrossReferenceField_CannotCrossFile = "Cross file reference not supported!"
Const TEXT_CreateReferencePoint_NothingSelected = "Nothing selected!"
Const TEXT_InsertCrossReferenceField_NoRefPoint = "No Reference Point Selected!"
Const TEXT_InsertCrossReferenceField_CannotCrossFile = "Cross file reference is not supported!"
Const TEXT_VersionPrompt = "Version: "
Const TEXT_NonCommecialPrompt = "Only for NON-COMMERCIAL use."

Const TEXT_RefBrokenComment = "Reference Broken!"
Const TEXT_BrokenRefFoundPrompt = BrokenRefNumPosHolder & " broken reference found, and comments are attached."
Const TEXT_NoBrokenRefFoundPrompt = "No broken reference found."
Const TEXT_RefBrokenCommentClearedPrompt = "Reference broken comments cleared."

#End If

Const BookmarkPrefix = "_HandyRef"

Public selectedBM As Bookmark
Public lastBMRefered As Boolean

Expand Down Expand Up @@ -133,6 +145,81 @@ noRefPointPrompt:
End If
End Sub

Public Sub HandyRef_ClearRefBrokenComment_RibbonFun(ByVal control As IRibbonControl)
HandyRef_ClearRefBrokenComment
MsgBox TEXT_RefBrokenCommentClearedPrompt, vbOKOnly, TEXT_HandyRefAppName
End Sub

Public Sub HandyRef_ClearRefBrokenComment()
Dim cmt As Comment
Dim s As String
For Each cmt In ActiveDocument.Comments
s = cmt.Range.Paragraphs.Last.Range.Text
s = Replace(s, vbCr, "")
s = Replace(s, vbLf, "")
If StrComp(s, RefBrokenCommentTitle) = 0 Then
cmt.DeleteRecursively
End If
Next cmt
End Sub

Public Sub HandyRef_CheckForBrokenRef_RibbonFun(ByVal control As IRibbonControl)
HandyRef_CheckForBrokenRef
End Sub

Public Sub HandyRef_CheckForBrokenRef()

HandyRef_ClearRefBrokenComment

Dim refRegExp As Object
Set refRegExp = CreateObject("VBScript.RegExp")
With refRegExp
.Global = False
.IgnoreCase = True
.Pattern = "\s*REF\s+([^\s]+)\s*.*"
End With

Dim brokenCount As Integer
brokenCount = 0

Dim fd As Field
Dim bmName As String
Dim cmt As Comment
For Each fd In ActiveDocument.Fields
If fd.Type = wdFieldRef Then
Set r = refRegExp.Execute(fd.Code.Text)
If r.Count > 0 Then
bmName = r.Item(0).SubMatches(0)
If Not ActiveDocument.Bookmarks.Exists(bmName) Then

brokenCount = brokenCount + 1

Set cmt = fd.Code.Comments.Add(fd.Code)
With cmt.Range
.InsertAfter TEXT_RefBrokenComment
.InsertParagraphAfter
.InsertAfter RefBrokenCommentTitle
End With

With cmt.Range.Paragraphs.First.Range
.Bold = True
.HighlightColorIndex = wdYellow
End With

End If
End If
End If
Next fd

If brokenCount = 0 Then
MsgBox TEXT_NoBrokenRefFoundPrompt, vbOKOnly, TEXT_HandyRefAppName
Else
MsgBox Replace(TEXT_BrokenRefFoundPrompt, BrokenRefNumPosHolder, CStr(brokenCount)), vbOKOnly, TEXT_HandyRefAppName
End If

End Sub



Public Sub HandyRef_About_RibbonFun(ByVal control As IRibbonControl)
HandyRef_About
Expand All @@ -144,3 +231,4 @@ Public Sub HandyRef_About()

End Sub


Binary file modified HandyRef/HandyRef-Dev.dotm
Binary file not shown.
6 changes: 4 additions & 2 deletions HandyRef/customUI/handyRefUI.en-us.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
<tabs>
<tab idMso="TabReferences">
<group id="HandyRefGroup" label="HandyRef">
<button id="HandyRef_CreateReferencePoint_Button" label="Create Reference Point" screentip="Create Reference Source Point (Ctrl + Alt + C)" size="large" imageMso="TableOfContentsAddTextGallery" onAction="HandyRef_CreateReferencePoint_RibbonFun" />
<button id="HandyRef_CreateReferencePoint_Button" label="Create Source" screentip="Create Reference Source Point (Ctrl + Alt + C)" size="large" imageMso="TableOfContentsAddTextGallery" onAction="HandyRef_CreateReferencePoint_RibbonFun" />
<button id="HandyRef_InsertCrossReferenceField_Button" label="Insert Reference" screentip="Insert Cross Reference (Ctrl + Alt + V)" size="large" imageMso="CrossReferenceInsert" onAction="HandyRef_InsertCrossReferenceField_RibbonFun" />
<button id="HandyRef_About_Button" label="About HandyRef" size="large" imageMso="Info" onAction="HandyRef_About_RibbonFun" />
<button id="HandyRef_CheckForBrokenRef_Button" label="Check Reference" screentip="Check for broken reference in the document and add comments for them" size="large" imageMso="ErrorChecking" onAction="HandyRef_CheckForBrokenRef_RibbonFun" />
<button id="HandyRef_ClearRefBrokenComment_Button" label="Clear Comments" screentip="Clear all reference broken comments" size="normal" imageMso="Clear" onAction="HandyRef_ClearRefBrokenComment_RibbonFun" />
<button id="HandyRef_About_Button" label="About HandyRef" size="normal" imageMso="Info" onAction="HandyRef_About_RibbonFun" />
</group >
</tab>
</tabs>
Expand Down
4 changes: 3 additions & 1 deletion HandyRef/customUI/handyRefUI.zh-cn.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
<group id="HandyRefGroup" label="HandyRef-快引">
<button id="HandyRef_CreateReferencePoint_Button" label="创建引用源" screentip="创建引用源 (Ctrl + Alt + C)" size="large" imageMso="TableOfContentsAddTextGallery" onAction="HandyRef_CreateReferencePoint_RibbonFun" />
<button id="HandyRef_InsertCrossReferenceField_Button" label="交叉引用" screentip="插入交叉引用 (Ctrl + Alt + V)" size="large" imageMso="CrossReferenceInsert" onAction="HandyRef_InsertCrossReferenceField_RibbonFun" />
<button id="HandyRef_About_Button" label="关于 快引" size="large" imageMso="Info" onAction="HandyRef_About_RibbonFun" />
<button id="HandyRef_CheckForBrokenRef_Button" label="检查引用" screentip="查找文档中是否存在损坏的引用,若找到将为其添加批注" size="large" imageMso="ErrorChecking" onAction="HandyRef_CheckForBrokenRef_RibbonFun" />
<button id="HandyRef_ClearRefBrokenComment_Button" label="清除批注" screentip="清除所有针对损坏引用的批注" size="normal" imageMso="Clear" onAction="HandyRef_ClearRefBrokenComment_RibbonFun" />
<button id="HandyRef_About_Button" label="关于“快引”" size="normal" imageMso="Info" onAction="HandyRef_About_RibbonFun" />
</group >
</tab>
</tabs>
Expand Down
2 changes: 1 addition & 1 deletion HandyRef/word/vbaData.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<wne:vbaSuppData xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex" xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex" xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex" xmlns:cx6="http://schemas.microsoft.com/office/drawing/2016/5/12/chartex" xmlns:cx7="http://schemas.microsoft.com/office/drawing/2016/5/13/chartex" xmlns:cx8="http://schemas.microsoft.com/office/drawing/2016/5/14/chartex" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:aink="http://schemas.microsoft.com/office/drawing/2016/ink" xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 w16se w16cid wp14"><wne:mcds><wne:mcd wne:macroName="HANDYREF.MAIN.HANDYREF_ABOUT" wne:name="HandyRef.Main.HandyRef_About" wne:bEncrypt="00" wne:cmg="56"/><wne:mcd wne:macroName="HANDYREF.MAIN.HANDYREF_CREATEREFERENCEPOINT" wne:name="HandyRef.Main.HandyRef_CreateReferencePoint" wne:bEncrypt="00" wne:cmg="56"/><wne:mcd wne:macroName="HANDYREF.MAIN.HANDYREF_INSERTCROSSREFERENCEFIELD" wne:name="HandyRef.Main.HandyRef_InsertCrossReferenceField" wne:bEncrypt="00" wne:cmg="56"/></wne:mcds></wne:vbaSuppData>
<wne:vbaSuppData xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex" xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex" xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex" xmlns:cx6="http://schemas.microsoft.com/office/drawing/2016/5/12/chartex" xmlns:cx7="http://schemas.microsoft.com/office/drawing/2016/5/13/chartex" xmlns:cx8="http://schemas.microsoft.com/office/drawing/2016/5/14/chartex" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:aink="http://schemas.microsoft.com/office/drawing/2016/ink" xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 w16se w16cid wp14"><wne:mcds><wne:mcd wne:macroName="HANDYREF.MAIN.HANDYREF_ABOUT" wne:name="HandyRef.Main.HandyRef_About" wne:bEncrypt="00" wne:cmg="56"/><wne:mcd wne:macroName="HANDYREF.MAIN.HANDYREF_CREATEREFERENCEPOINT" wne:name="HandyRef.Main.HandyRef_CreateReferencePoint" wne:bEncrypt="00" wne:cmg="56"/><wne:mcd wne:macroName="HANDYREF.MAIN.HANDYREF_INSERTCROSSREFERENCEFIELD" wne:name="HandyRef.Main.HandyRef_InsertCrossReferenceField" wne:bEncrypt="00" wne:cmg="56"/><wne:mcd wne:macroName="HANDYREF.MAIN.HANDYREF_CHECKFORBROKENREF" wne:name="HandyRef.Main.HandyRef_CheckForBrokenRef" wne:bEncrypt="00" wne:cmg="56"/><wne:mcd wne:macroName="HANDYREF.MAIN.HANDYREF_CLEARREFBROKENCOMMENT" wne:name="HandyRef.Main.HandyRef_ClearRefBrokenComment" wne:bEncrypt="00" wne:cmg="56"/></wne:mcds></wne:vbaSuppData>
Binary file modified HandyRef/word/vbaProject.en-us.bin
Binary file not shown.
Binary file modified HandyRef/word/vbaProject.zh-cn.bin
Binary file not shown.
Loading

0 comments on commit f8aa962

Please sign in to comment.