Skip to content

Commit

Permalink
Improved version of GAUG_removeHyperlinksForCitations
Browse files Browse the repository at this point in the history
GAUG_removeHyperlinksForCitations can now be executed in three different ways depending on a parameter.

The parameter strTypeOfExecution can have one of three different values:
"RemoveHyperlinks":
UNEXPECTED RESULTS IF MANUAL MODIFICATIONS EXIST, BUT THE FASTEST. Removes the bookmarks and hyperlinks. Manual modifications to citations and bibliography will remain intact.
"CleanEnvironment":
EXPERIMENTAL, BUT VERY FAST. Removes the bookmarks and hyperlinks. Manual modifications to citations and bibliography will also be removed to have a clean environment
"CleanFullEnvironment":
SAFE, BUT VERY SLOW IN LONG DOCUMENTS. Removes the bookmarks and hyperlinks. Manual modifications to citations and bibliography will also be removed to have a clean environment.
  • Loading branch information
mabentwickeltsich authored Jan 11, 2017
1 parent 50a7682 commit 2c53673
Showing 1 changed file with 148 additions and 13 deletions.
161 changes: 148 additions & 13 deletions macros.vba
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'*****************************************************************************************
'*****************************************************************************************
'** Author: José Luis González García **
'** Last modified: 2016-12-28 **
'** Last modified: 2017-01-11 **
'** **
'** Sub GAUG_createHyperlinksForCitationsAPA() **
'** **
Expand All @@ -26,7 +26,9 @@ Sub GAUG_createHyperlinksForCitationsAPA()
'*****************************
'* Cleaning old hyperlinks *
'*****************************
GAUG_removeHyperlinksForCitations
'possible values are "RemoveHyperlinks", "CleanEnvironment" and "CleanFullEnvironment"
'SEE DOCUMENTATION
Call GAUG_removeHyperlinksForCitations("RemoveHyperlinks")



Expand Down Expand Up @@ -307,7 +309,7 @@ End Sub
'*****************************************************************************************
'*****************************************************************************************
'** Author: José Luis González García **
'** Last modified: 2016-12-28 **
'** Last modified: 2017-01-11 **
'** **
'** Sub GAUG_createHyperlinksForCitationsIEEE() **
'** **
Expand All @@ -328,7 +330,9 @@ Sub GAUG_createHyperlinksForCitationsIEEE()
'*****************************
'* Cleaning old hyperlinks *
'*****************************
GAUG_removeHyperlinksForCitations
'possible values are "RemoveHyperlinks", "CleanEnvironment" and "CleanFullEnvironment"
'SEE DOCUMENTATION
Call GAUG_removeHyperlinksForCitations("RemoveHyperlinks")



Expand Down Expand Up @@ -467,25 +471,67 @@ End Sub
'*****************************************************************************************
'*****************************************************************************************
'** Author: José Luis González García **
'** Last modified: 2016-12-28 **
'** Last modified: 2017-01-11 **
'** **
'** Sub GAUG_removeHyperlinksForCitations() **
'** Sub GAUG_removeHyperlinksForCitations(strTypeOfExecution As String) **
'** **
'** Removes the bookmarks generated by GAUG_createHyperlinksForCitations **
'** This is an improved version which runs much faster, **
'** but still considered as experimental. **
'** Make sure you have a backup of your document before you execute it! **
'** **
'** Removes the bookmarks generated by GAUG_createHyperlinksForCitations* **
'** in the bibliography inserted by Mendeley's plugin. **
'** Removes the hyperlinks generated by GAUG_createHyperlinksForCitations **
'** Removes the hyperlinks generated by GAUG_createHyperlinksForCitations* **
'** of the citations inserted by Mendeley's plugin. **
'** Removes all manual modifications to the citations and bibliography if specified **
'** **
'** Parameter strTypeOfExecution can have three different values: **
'** "RemoveHyperlinks": **
'** UNEXPECTED RESULTS IF MANUAL MODIFICATIONS EXIST, BUT THE FASTEST **
'** Removes the bookmarks and hyperlinks **
'** Manual modifications to citations and bibliography will remain intact **
'** "CleanEnvironment": **
'** EXPERIMENTAL, BUT VERY FAST **
'** Removes the bookmarks and hyperlinks **
'** Manual modifications to citations and bibliography will also be removed **
'** to have a clean environment **
'** "CleanFullEnvironment": **
'** SAFE, BUT VERY SLOW IN LONG DOCUMENTS **
'** Removes the bookmarks and hyperlinks **
'** Manual modifications to citations and bibliography will also be removed **
'** to have a clean environment **
'*****************************************************************************************
'*****************************************************************************************
Sub GAUG_removeHyperlinksForCitations()
Sub GAUG_removeHyperlinksForCitations(Optional ByVal strTypeOfExecution As String = "RemoveHyperlinks")
Dim documentSection As Section
Dim sectionField As Field
Dim fieldBookmark As Bookmark
Dim selectionHyperlinks As Hyperlinks
Dim i As Integer
Dim blnFound As Boolean
Dim sectionFieldName, sectionFieldNewName As String
Dim objMendeleyApiClient As Object
Dim cbbUndoEditButton As CommandBarButton


'disables the screen updating while removing the hyperlinks to increase speed
Application.ScreenUpdating = False

'selects the type of execution
Select Case strTypeOfExecution
Case "RemoveHyperlinks"
'nothing to do here
Case "CleanEnvironment"
'get the API Client from Mendeley
Set objMendeleyApiClient = Application.Run("Mendeley.mendeleyApiClient") 'MabEntwickeltSich: This is the way to call the macro directly from Mendeley
Case "CleanFullEnvironment"
'gets the Undo Edit Button
Set cbbUndoEditButton = Application.Run("MendeleyLib.getUndoEditButton") 'MabEntwickeltSich: This is the way to call the macro directly from Mendeley
Case Else
'the execution option is not correct
Exit Sub
End Select

'*****************************
'* Cleaning old hyperlinks *
'*****************************
Expand All @@ -494,9 +540,31 @@ Sub GAUG_removeHyperlinksForCitations()
For Each sectionField In documentSection.Range.Fields
'if it is a citation
If sectionField.Type = wdFieldAddin And Left(sectionField.Code, 18) = "ADDIN CSL_CITATION" Then
'tries to restore it to its original value, first with the whole field
sectionField.Select
GAUG_getUndoEditButton().Execute

'selects the type of execution to remove hyperlinks
Select Case strTypeOfExecution
Case "RemoveHyperlinks"
'gets all hyperlinks from selection
Set selectionHyperlinks = Selection.Hyperlinks
'deletes all hyperlinks
For i = selectionHyperlinks.Count To 1 Step -1
'deletes the current hyperlink
selectionHyperlinks(1).Delete
Next
Case "CleanEnvironment"
'copied from Mendeley.undoEdit(), but removing the code that updates the toolbar in Microsoft Word (making the original function very slow)
'restores the citations to the original state (deletes hyperlinks)
sectionFieldName = Application.Run("ZoteroLib.getMarkName", sectionField)
sectionFieldNewName = objMendeleyApiClient.undoManualFormat(sectionFieldName)
Call Application.Run("ZoteroLib.fnRenameMark", sectionField, sectionFieldNewName) 'MabEntwickeltSich: This is another way to call the macro directly from Mendeley
Call Application.Run("ZoteroLib.subSetMarkText", sectionField, INSERT_CITATION_TEXT) 'MabEntwickeltSich: This is another way to call the macro directly from Mendeley
Case "CleanFullEnvironment"
'restores the citations to the original state (deletes hyperlinks)
'slow version
cbbUndoEditButton.Execute
End Select

End If
Next

Expand All @@ -516,8 +584,8 @@ Sub GAUG_removeHyperlinksForCitations()
For Each sectionField In documentSection.Range.Fields
'if it is the bibliography
If sectionField.Type = wdFieldAddin And Trim(sectionField.Code) = "ADDIN Mendeley Bibliography CSL_BIBLIOGRAPHY" Then
'deletes old bookmarks
sectionField.Select
'deletes all bookmarks
For Each fieldBookmark In Selection.Bookmarks
'deletes current bookmark
fieldBookmark.Delete
Expand All @@ -528,20 +596,87 @@ Sub GAUG_removeHyperlinksForCitations()

Next

'selects the type of execution
Select Case strTypeOfExecution
Case "RemoveHyperlinks"
'nothing to do here
Case "CleanEnvironment"
'copied from Mendeley.undoEdit(), but removing the code that updates the toolbar in Microsoft Word (making the original function very slow)
Call Application.Run("MendeleyLib.refreshDocument") 'MabEntwickeltSich: This is another way to call the macro directly from Mendeley
Case "CleanFullEnvironment"
'nothing to do here
End Select

'reenables the screen updating
Application.ScreenUpdating = True

End Sub



'*****************************************************************************************
'*****************************************************************************************
'** Author: José Luis González García **
'** Last modified: 2017-01-11 **
'** **
'** Sub GAUG_removeHyperlinks() **
'** **
'** Calls Sub GAUG_removeHyperlinksForCitations(strTypeOfExecution As String) **
'** with parameter strTypeOfExecution = "RemoveHyperlinks" **
'*****************************************************************************************
'*****************************************************************************************
Sub GAUG_removeHyperlinks()
'removes all bookmarks and hyperlinks from the citations and bibliography
Call GAUG_removeHyperlinksForCitations("RemoveHyperlinks")
End Sub



'*****************************************************************************************
'*****************************************************************************************
'** Author: José Luis González García **
'** Last modified: 2017-01-11 **
'** **
'** Sub GAUG_cleanEnvironment() **
'** **
'** Calls Sub GAUG_removeHyperlinksForCitations(strTypeOfExecution As String) **
'** with parameter strTypeOfExecution = "CleanFullEnvironment" **
'*****************************************************************************************
'*****************************************************************************************
Sub GAUG_cleanEnvironment()
'removes all bookmarks, hyperlinks and manual modifications to the citations and bibliography
Call GAUG_removeHyperlinksForCitations("CleanEnvironment")
End Sub



'*****************************************************************************************
'*****************************************************************************************
'** Author: José Luis González García **
'** Last modified: 2017-01-11 **
'** **
'** Sub GAUG_cleanFullEnvironment() **
'** **
'** Calls Sub GAUG_removeHyperlinksForCitations(strTypeOfExecution As String) **
'** with parameter strTypeOfExecution = "CleanFullEnvironment" **
'*****************************************************************************************
'*****************************************************************************************
Sub GAUG_cleanFullEnvironment()
'removes all bookmarks, hyperlinks and manual modifications to the citations and bibliography
Call GAUG_removeHyperlinksForCitations("CleanFullEnvironment")
End Sub



'*****************************************************************************************
'*****************************************************************************************
'** Author: Mendeley **
'** Last modified: 2016-04-26 **
'** Last modified: 2017-01-11 **
'** **
'** Function GAUG_getUndoEditButton() As CommandBarButton **
'** **
'** This functions is not used anymore in any fo the GAUG_* functions **
'** **
'** Gets the CommandBarButton "Undo Edit" installed by Mendeley's plugin. **
'** The CommandBarButton is used to restore the original citation fields **
'** inserted by Mendeley. **
Expand Down

0 comments on commit 2c53673

Please sign in to comment.