Skip to content

Instantly share code, notes, and snippets.

@JMichaelTX
Created January 24, 2016 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JMichaelTX/df13b696726953381cf4 to your computer and use it in GitHub Desktop.
Save JMichaelTX/df13b696726953381cf4 to your computer and use it in GitHub Desktop.
Open Evernote Classic (local) Link in MIcrosoft Word 2011 Mac Using Word VBA
Private Declare Function system Lib "libc.dylib" (ByVal command As String) As Long '*** system docs here: http://pubs.opengroup.org/onlinepubs/9699919799/ Sub OpenURL(pURL As String) '================================================================ ' OpenURL Sub Procedure ' ' VER: 1.0 DATE: 2016-01-23 ' ' PURPOSE: Open any URL (including custom protocols) using Mac system "open" command ' ' REQUIRES: ' This function at top of module: ' Private Declare Function system Lib "libc.dylib" (ByVal command As String) As Long ' ' REF: ' 1. How to Use the system() function from the standard C library in a VBA Macro ' http://stackoverflow.com/a/12320294/915019 ' BY: Robert Knight '================================================================ Dim result As Long Dim CMDStr As String CMDStr = "open " & pURL result = system(CMDStr) Debug.Print Str(result) End Sub Sub OpenEvernoteNote() '================================================================ ' OpenEvernoteNote Sub Procedure ' ' VER: 1.0 DATE: 2016-01-23 ' ' PURPOSE: Open Evernote Note in a new window using Local EN Mac app ' ' HOW TO USE: ' ' 1. Create a hyperlink in Word using the local Evernote URL (evernote:///) ' • In EN Mac, right-click on Note in list, hold down OPTION key, and ' select "Copy Classic Note Link" ' • Type Note title in Word, select, ' press CMD+K to create hyperlink ' Paste link from clipboard ' • Word will change the URL, but ignore that ' OR ' Use this AppleScript to create RTF link and paste into Word: ' • Copy EN Note Link (Classic) AS.scpt ' https://gist.github.com/JMichaelTX/0b14e9755ed77f347816 ' ' 2. Select this hyperlink, or just place the cursor anywhere within the link text ' 3. Run this macro ' ' AUTHOR: ' JMichaelTX ' ' REQUIRES: ' • Sub OpenURL() ' • Private Declare Function system Lib "libc.dylib" (ByVal command As String) As Long ' ' REF: ' 1. How to Use the system() function from the standard C library in a VBA Macro ' http://stackoverflow.com/a/12320294/915019 ' BY: Robert Knight ' ' COMMENTS: ' • Any attempt to use the Word built-in hyperlink function (from the UI or VBA) will result in Word ' changing any URL protocol (like evernote:///) to a file protocol (file:///). ' • Thus we can NOT use any of the Word hyperlink features, except as a tool ' to show friendly text and hide long URLs ' • The ONLY choice I have found is to call a Mac system function to "open" the custom URL. ' '================================================================= ' Dim URL As String '*** YOU MUST FIRST HAVE SELECTED OR PUT CURSOR IN THE HYPERLINK *** URL = "" On Error Resume Next URL = Selection.Hyperlinks(1).Address '** GET the URL in the Word hyperlink object ** posEN = InStr(URL, "evernote") '--- CHECK FOR EVERNOTE URL PROTOCOL --- If (posEN = 0) Then MsgBox ("'evernote' protocol NOT found. " _ & vbCr & "Make sure you have selected hyperlink with an Evernote protocol: 'evernote:///'" _ & vbCr & "Exiting macro.") Exit Sub End If URL = Mid(URL, posEN) '** Remove all text prior to the word "evernote" ** URL = Replace(URL, ":", "/") '** Replace all colons with forward slashes ** URL = Replace(URL, "evernote/", "evernote:") '** Replace the slash after "evernote" with a colon ** '--- The evernote URL protocol is now in proper format --- Debug.Print URL Call OpenURL(URL) '** Open the Evernote Note in its own window ** End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment