Macro to open a web URL from Outlook
Published:
| by Julian Knight Reading time ~1 min.
📖 Kb
| 📎
Development, Microsoft, Software
| 🔖
Microsoft, Office, Outlook, VBA
Many of us spend most of our work time in a few applications such as Outlook (email) and a web browser. This example macro for Microsoft Outlook will let you add a button to the Outlook Ribbon that will open a specific website URL.
To use this macro:
- Open the VBA Editor window (ctrl-F11)
- Double-click on Project1 > Microsoft Outlook Objects > ThisOutlookSession in the Project pane (top-left)
- Paste the code below
- Customise the Ribbon
- Add a new Group (you can’t add your own entries to the standard groups)
- Add the
openGoogle
macro (or whatever you’ve added), rename and change the icon if desired
Note: This version will only work for the 64-bit version of Microsoft Outlook.
To use on the 32-bit version, remove the word PtrSafe
.
Option Explicit
Private Declare PtrSafe Function ShellExecute _
Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hWnd As Long, _
ByVal Operation As String, _
ByVal Filename As String, _
Optional ByVal Parameters As String, _
Optional ByVal Directory As String, _
Optional ByVal WindowStyle As Long = vbMinimizedFocus _
) As Long
' WARINING: THIS MUST ONLY BE GIVEN SAFE URLs!
' DO NOT USE WITH DIRECT USER INPUT
Private Sub openUrl(url As String)
Dim lSuccess As Long
lSuccess = ShellExecute(0, "Open", url)
End Sub
Public Sub openGoogle()
openUrl "https://google.com"
End Sub