Results 1 to 8 of 8

Thread: Translating Word VBA into Outlook VBA

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Translating Word VBA into Outlook VBA

    [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
    Last edited by acantor; 11-13-2017 at 01:41 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •