I am Using: Outlook office for 365 (desktop)
I am trying to have a VB macro that on running should copy the selected text and put it into a predefined web address and open it in the default browser.
Steps:
- Open or select a received message
- Select a word from the email (the selected word could be in the subject or body of the email)
- Run the macro
- The default browser should open the link: https://www.dictionary.com/browse/*selected word*
The code so far I have is the one shown below. However, this only opens the link when the selected word is in the body of the email.
Sub OPEN_DICT()
Dim msg As Outlook.MailItem
Dim insp As Outlook.Inspector
Dim vURL1
Dim vURL2
Dim fullVID
Dim fullVURL
If Application.ActiveInspector Is Nothing Then
If Application.ActiveExplorer.Selection.Count = 1 Then
If Application.ActiveExplorer.Selection.Item(1).Class = olMail Then
Set msg = Application.ActiveExplorer.Selection.Item(1)
End If
Else
'to many items selected
MsgBox "Please select one item"
End If
Else
Set insp = Application.ActiveInspector
If insp.CurrentItem.Class = olMail Then
Set msg = insp.CurrentItem
End If
End If
If msg Is Nothing Then
MsgBox "could not determine an item. Try again!"
Else
If msg.GetInspector.EditorType = olEditorWord Then
Set hed = msg.GetInspector.WordEditor
Set appWord = hed.Application
Set Rng = appWord.Selection
With Rng
.Copy
End With
End If
End If
If IsNumeric(Rng) Then
fullVID = Rng
vURL1 = "https://www.dictionary.com/browse/"
vURL2 = fullVID
fullVURL = vURL1 & vURL2
Else
fullVID = Rng
vURL1 = "https://www.dictionary.com/browse/"
vURL2 = fullVID
fullVURL = vURL1 & vURL2
End If
Dim build
Set build = CreateObject("Shell.Application")
build.ShellExecute "Chrome.exe", fullVURL, "", "", 1
ExitNewItem:
Exit Sub
Set appWord = Nothing
Set insp = Nothing
Set Rng = Nothing
Set hed = Nothing
Set msg = Nothing
End Sub
Can someone please help me in adjusting the macro so that the selected text from the Subject of the email can also be opened in the link? Also, instead of opening the link in Chrome, it should open in the default browser?
I am sorry if this is too much to ask. I am very new to macros and somehow learning, copy-pasting and trying. Need a big help here! THANKS!