- Alt+F11
- Insert > Module
- Past
macro.vbs
Created
June 25, 2019 16:16
-
-
Save timendum/4bdcd218cf2bc73174b2cf52905e59ff to your computer and use it in GitHub Desktop.
Generate a link from Outlook mail item and copy to clipboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'Adds a link to the currently selected message to the clipboard | |
Option Explicit | |
Private Declare Function OpenClipboard Lib "user32.dll" (ByVal hWnd As Long) As Long | |
Private Declare Function EmptyClipboard Lib "user32.dll" () As Long | |
Private Declare Function CloseClipboard Lib "user32.dll" () As Long | |
Private Declare Function SetClipboardData Lib "user32.dll" (ByVal wFormat As Long, ByVal hMem As Long) As Long | |
Private Declare Function GlobalAlloc Lib "kernel32.dll" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long | |
Private Declare Function GlobalLock Lib "kernel32.dll" (ByVal hMem As Long) As Long | |
Private Declare Function GlobalUnlock Lib "kernel32.dll" (ByVal hMem As Long) As Long | |
Private Declare Function GlobalSize Lib "kernel32" (ByVal hMem As Long) As Long | |
Private Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrcpyW" (ByVal lpString1 As Long, ByVal lpString2 As Long) As Long | |
Public Sub SetClipboard(sUniText As String) | |
Dim iStrPtr As Long | |
Dim iLen As Long | |
Dim iLock As Long | |
Const GMEM_MOVEABLE As Long = &H2 | |
Const GMEM_ZEROINIT As Long = &H40 | |
Const CF_UNICODETEXT As Long = &HD | |
OpenClipboard 0& | |
EmptyClipboard | |
iLen = LenB(sUniText) + 2& | |
iStrPtr = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, iLen) | |
iLock = GlobalLock(iStrPtr) | |
lstrcpy iLock, StrPtr(sUniText) | |
GlobalUnlock iStrPtr | |
SetClipboardData CF_UNICODETEXT, iStrPtr | |
CloseClipboard | |
End Sub | |
Sub AddLinkToMessageInClipboard() | |
Dim objMail As Outlook.MailItem | |
'One and ONLY one message muse be selected | |
If Application.ActiveExplorer.Selection.Count <> 1 Then | |
MsgBox ("Select one and ONLY one message.") | |
Exit Sub | |
End If | |
Set objMail = Application.ActiveExplorer.Selection.Item(1) | |
SetClipboard ("onenote:outlook?folder=Calendar&entryid=" + objMail.EntryID) | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment