[Edited: I made the code a little more bulletproof]
I scripted two VBA macros for Word documents that I am hoping to make functional in Outlook messages.
Both commands search for a two-letter string; select the entire word that contains the string, and then copies the word to the clipboard.
I am having a devil of a time "translating" my Word VBA into Outlook VBA. Can anyone give me a few clues?
Word script 1:
Sub Macro11()
' Collapse the selection to the right, and toggle off Extend mode.
Selection.Collapse Direction:=wdCollapseEnd
Selection.ExtendMode = False
' For testing: specify a search string. In the final version, Dragon will provide the value.
Dim x As String
Let x = "an" ' Search string
' Search forward for x, and wrap to top if not found.
Selection.Find.ClearFormatting
With Selection.Find
.Text = x
.Forward = True
.Wrap = wdFindContinue
.Execute
End With
' If text is selected (presumedly because the search string was found) select the entire word and copy it to the clipboard
If Len(Selection) > 1 Then
Selection.Extend
Selection.Extend
Selection.Copy
Else
Beep
End If
End Sub
Word Script 2:
Sub Macro13()
' Collapse the selection to the right, and toggle off Extend mode.
Selection.Collapse Direction:=wdCollapseEnd
Selection.ExtendMode = False
' Redo the most recent search
With Selection.Find
.Forward = True
.Wrap = wdFindContinue
.Execute
End With
' If text is selected (presumedly because the search string was found) select the entire word and copy it to the clipboard
If Len(Selection) > 1 Then
Selection.Extend
Selection.Extend
Selection.Copy
Else
Beep
End If
End Sub