Search currently viewed email for a specific phrase, fetch a string to copy to clipboard












0















I get assignments in emails that come to a shared Outlook mailbox.



In a typical email there are multiple strings and variables regarding a client, including their name, date and ID with a hyphen that I also want to get rid of.



There are two types of IDs. Both consist of 8 numbers and a hyphen, e.g. 1234567-8 and 123456-78. Sometimes there is a character in front of the number so I believe storing data in string is a must. I want to make several copies of the macro for each type of data. I want it all in a simple string form as I want to copy it to clipboard and paste elsewhere and have no need to process it further.



The code below does all I want except it stores the data in variables instead of string and does not remove the hyphen.



Code courtesy of vbaexpress' gmayor.



Option Explicit

Sub GetCustomer()
Dim olItem As Outlook.MailItem
Dim olInsp As Outlook.Inspector
Dim dCust As DataObject
Dim wdDoc As Object
Dim oRng As Object
Dim sCustomer As String
Dim bFound As Boolean
On Error GoTo lbl_Exit
Set olItem = ActiveExplorer.Selection.Item(1)
With olItem
Set olInsp = .GetInspector
Set wdDoc = olInsp.WordEditor
Set oRng = wdDoc.Range
With oRng.Find
Do While .Execute(findText:="Customer #:[ 0-9]{2,}", MatchWildcards:=True)
sCustomer = Trim(Split(oRng.Text, Chr(58))(1))
bFound = True
Set dCust = New DataObject
dCust.SetText sCustomer
dCust.PutInClipboard
MsgBox "Customer number '" & sCustomer & "' copied to clipboard"
Exit Do
Loop
End With
If Not bFound Then MsgBox "Customer number not found"
End With
lbl_Exit:
Set olItem = Nothing
Set olInsp = Nothing
Set wdDoc = Nothing
Set oRng = Nothing
Set dCust = Nothing
Exit Sub
End Sub


I want to search the currently previewed email (if that is possible), without actually opening it in another separate window, for a phrase like



"Customer ID:           123456-78"


and reformat the last part by simply removing the hyphen and disregarding the first part



"Customer ID:           " 


(there is a giant space between the Customer ID and the number).



I also want to reformat the date from 11.22.2019 to 2019-22-11 and also copy it to clipboard.










share|improve this question





























    0















    I get assignments in emails that come to a shared Outlook mailbox.



    In a typical email there are multiple strings and variables regarding a client, including their name, date and ID with a hyphen that I also want to get rid of.



    There are two types of IDs. Both consist of 8 numbers and a hyphen, e.g. 1234567-8 and 123456-78. Sometimes there is a character in front of the number so I believe storing data in string is a must. I want to make several copies of the macro for each type of data. I want it all in a simple string form as I want to copy it to clipboard and paste elsewhere and have no need to process it further.



    The code below does all I want except it stores the data in variables instead of string and does not remove the hyphen.



    Code courtesy of vbaexpress' gmayor.



    Option Explicit

    Sub GetCustomer()
    Dim olItem As Outlook.MailItem
    Dim olInsp As Outlook.Inspector
    Dim dCust As DataObject
    Dim wdDoc As Object
    Dim oRng As Object
    Dim sCustomer As String
    Dim bFound As Boolean
    On Error GoTo lbl_Exit
    Set olItem = ActiveExplorer.Selection.Item(1)
    With olItem
    Set olInsp = .GetInspector
    Set wdDoc = olInsp.WordEditor
    Set oRng = wdDoc.Range
    With oRng.Find
    Do While .Execute(findText:="Customer #:[ 0-9]{2,}", MatchWildcards:=True)
    sCustomer = Trim(Split(oRng.Text, Chr(58))(1))
    bFound = True
    Set dCust = New DataObject
    dCust.SetText sCustomer
    dCust.PutInClipboard
    MsgBox "Customer number '" & sCustomer & "' copied to clipboard"
    Exit Do
    Loop
    End With
    If Not bFound Then MsgBox "Customer number not found"
    End With
    lbl_Exit:
    Set olItem = Nothing
    Set olInsp = Nothing
    Set wdDoc = Nothing
    Set oRng = Nothing
    Set dCust = Nothing
    Exit Sub
    End Sub


    I want to search the currently previewed email (if that is possible), without actually opening it in another separate window, for a phrase like



    "Customer ID:           123456-78"


    and reformat the last part by simply removing the hyphen and disregarding the first part



    "Customer ID:           " 


    (there is a giant space between the Customer ID and the number).



    I also want to reformat the date from 11.22.2019 to 2019-22-11 and also copy it to clipboard.










    share|improve this question



























      0












      0








      0


      1






      I get assignments in emails that come to a shared Outlook mailbox.



      In a typical email there are multiple strings and variables regarding a client, including their name, date and ID with a hyphen that I also want to get rid of.



      There are two types of IDs. Both consist of 8 numbers and a hyphen, e.g. 1234567-8 and 123456-78. Sometimes there is a character in front of the number so I believe storing data in string is a must. I want to make several copies of the macro for each type of data. I want it all in a simple string form as I want to copy it to clipboard and paste elsewhere and have no need to process it further.



      The code below does all I want except it stores the data in variables instead of string and does not remove the hyphen.



      Code courtesy of vbaexpress' gmayor.



      Option Explicit

      Sub GetCustomer()
      Dim olItem As Outlook.MailItem
      Dim olInsp As Outlook.Inspector
      Dim dCust As DataObject
      Dim wdDoc As Object
      Dim oRng As Object
      Dim sCustomer As String
      Dim bFound As Boolean
      On Error GoTo lbl_Exit
      Set olItem = ActiveExplorer.Selection.Item(1)
      With olItem
      Set olInsp = .GetInspector
      Set wdDoc = olInsp.WordEditor
      Set oRng = wdDoc.Range
      With oRng.Find
      Do While .Execute(findText:="Customer #:[ 0-9]{2,}", MatchWildcards:=True)
      sCustomer = Trim(Split(oRng.Text, Chr(58))(1))
      bFound = True
      Set dCust = New DataObject
      dCust.SetText sCustomer
      dCust.PutInClipboard
      MsgBox "Customer number '" & sCustomer & "' copied to clipboard"
      Exit Do
      Loop
      End With
      If Not bFound Then MsgBox "Customer number not found"
      End With
      lbl_Exit:
      Set olItem = Nothing
      Set olInsp = Nothing
      Set wdDoc = Nothing
      Set oRng = Nothing
      Set dCust = Nothing
      Exit Sub
      End Sub


      I want to search the currently previewed email (if that is possible), without actually opening it in another separate window, for a phrase like



      "Customer ID:           123456-78"


      and reformat the last part by simply removing the hyphen and disregarding the first part



      "Customer ID:           " 


      (there is a giant space between the Customer ID and the number).



      I also want to reformat the date from 11.22.2019 to 2019-22-11 and also copy it to clipboard.










      share|improve this question
















      I get assignments in emails that come to a shared Outlook mailbox.



      In a typical email there are multiple strings and variables regarding a client, including their name, date and ID with a hyphen that I also want to get rid of.



      There are two types of IDs. Both consist of 8 numbers and a hyphen, e.g. 1234567-8 and 123456-78. Sometimes there is a character in front of the number so I believe storing data in string is a must. I want to make several copies of the macro for each type of data. I want it all in a simple string form as I want to copy it to clipboard and paste elsewhere and have no need to process it further.



      The code below does all I want except it stores the data in variables instead of string and does not remove the hyphen.



      Code courtesy of vbaexpress' gmayor.



      Option Explicit

      Sub GetCustomer()
      Dim olItem As Outlook.MailItem
      Dim olInsp As Outlook.Inspector
      Dim dCust As DataObject
      Dim wdDoc As Object
      Dim oRng As Object
      Dim sCustomer As String
      Dim bFound As Boolean
      On Error GoTo lbl_Exit
      Set olItem = ActiveExplorer.Selection.Item(1)
      With olItem
      Set olInsp = .GetInspector
      Set wdDoc = olInsp.WordEditor
      Set oRng = wdDoc.Range
      With oRng.Find
      Do While .Execute(findText:="Customer #:[ 0-9]{2,}", MatchWildcards:=True)
      sCustomer = Trim(Split(oRng.Text, Chr(58))(1))
      bFound = True
      Set dCust = New DataObject
      dCust.SetText sCustomer
      dCust.PutInClipboard
      MsgBox "Customer number '" & sCustomer & "' copied to clipboard"
      Exit Do
      Loop
      End With
      If Not bFound Then MsgBox "Customer number not found"
      End With
      lbl_Exit:
      Set olItem = Nothing
      Set olInsp = Nothing
      Set wdDoc = Nothing
      Set oRng = Nothing
      Set dCust = Nothing
      Exit Sub
      End Sub


      I want to search the currently previewed email (if that is possible), without actually opening it in another separate window, for a phrase like



      "Customer ID:           123456-78"


      and reformat the last part by simply removing the hyphen and disregarding the first part



      "Customer ID:           " 


      (there is a giant space between the Customer ID and the number).



      I also want to reformat the date from 11.22.2019 to 2019-22-11 and also copy it to clipboard.







      vba string outlook outlook-vba






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 8 at 3:49









      Community

      11




      11










      asked Jan 3 at 17:06









      hollsonhollson

      32




      32
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Searches based on wildcards are limited to what wildcards can provide, which is better than nothing, but still not very much.



          Outlook uses Word functions for this, so that the VBA documentation for Word applies. Applicable wildcards themselves are can be seen using the "Special" button in the "Find" dialog (F4 in Outlook), after "use wildcards" has been checked.



          To my knowledge there is no concept of "optional" parts in wildcard searches, which means you need to try more than one wildcard pattern to cover your "sometimes there is a letter in front" case.



          So the general approach, based this knowledge and on your sample code, would be




          • Pick the currently selected MailItem in the ActiveExplorer

          • For each predefined wildcard pattern


            • reset the search range to the whole email

            • execute wildcard search

            • as long as there are search hits


              • display result, let user pick or cancel the search






          This way multiple patterns can be defined and you have a chance to continue to the next hit if the first hit is a false positive.



          I found the pattern [0-9-]{8;9} plus MatchWholeWord to work reasonably well (blocks of digits and dashes, between 8 or 9 characters long), but real life data often has surprises. You will probably need to add more patterns. Watch out: for me, Outlook wants ; instead of ,. This might be dependent on the system locale, I'm not sure.



          Also I'm not a fan of a "silent" On Error Resume. If there is an error, I prefer to see an error actual message. If there is a condition that can be checked in order to prevent an error, I prefer to check for this condition explicitly. This makes the code more robust and debugging easier. My Sub does not contain an On Error line for that reason.



          In code, this would look like this:



          Sub GetCustomer()
          Dim olItem As Outlook.MailItem
          Dim oRng As Object
          Dim sCustomer As String
          Dim patterns As Variant, pattern As Variant
          Dim answer As VbMsgBoxResult

          ' bail out if the preconditions are not right
          If ActiveExplorer.Selection.Count = 0 Then Exit Sub
          If Not (TypeOf ActiveExplorer.Selection.item(1) Is MailItem) Then Exit Sub

          Set olItem = ActiveExplorer.Selection.item(1)
          Set oRng = olItem.GetInspector.WordEditor.Range

          ' add more wildcard patterns in descending order of likelyhood
          patterns = Array("[0-9-]{8;9}", "[A-Z][0-9-]{8;9}")

          For Each pattern In patterns
          oRng.WholeStory
          While oRng.Find.Execute(findText:=pattern, MatchWildcards:=True, MatchWholeWord:=True)
          answer = MsgBox(oRng.Text, vbYesNoCancel + vbQuestion, "Customer Number")
          If answer = vbYes Then
          With New DataObject
          .SetText oRng.Text
          .PutInClipboard
          End With
          Exit For
          ElseIf answer = vbCancel Then
          Exit For
          End If
          Wend
          Next pattern
          End Sub


          Setting variables to Nothing at the end of the function is superfluous.






          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54026731%2fsearch-currently-viewed-email-for-a-specific-phrase-fetch-a-string-to-copy-to-c%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Searches based on wildcards are limited to what wildcards can provide, which is better than nothing, but still not very much.



            Outlook uses Word functions for this, so that the VBA documentation for Word applies. Applicable wildcards themselves are can be seen using the "Special" button in the "Find" dialog (F4 in Outlook), after "use wildcards" has been checked.



            To my knowledge there is no concept of "optional" parts in wildcard searches, which means you need to try more than one wildcard pattern to cover your "sometimes there is a letter in front" case.



            So the general approach, based this knowledge and on your sample code, would be




            • Pick the currently selected MailItem in the ActiveExplorer

            • For each predefined wildcard pattern


              • reset the search range to the whole email

              • execute wildcard search

              • as long as there are search hits


                • display result, let user pick or cancel the search






            This way multiple patterns can be defined and you have a chance to continue to the next hit if the first hit is a false positive.



            I found the pattern [0-9-]{8;9} plus MatchWholeWord to work reasonably well (blocks of digits and dashes, between 8 or 9 characters long), but real life data often has surprises. You will probably need to add more patterns. Watch out: for me, Outlook wants ; instead of ,. This might be dependent on the system locale, I'm not sure.



            Also I'm not a fan of a "silent" On Error Resume. If there is an error, I prefer to see an error actual message. If there is a condition that can be checked in order to prevent an error, I prefer to check for this condition explicitly. This makes the code more robust and debugging easier. My Sub does not contain an On Error line for that reason.



            In code, this would look like this:



            Sub GetCustomer()
            Dim olItem As Outlook.MailItem
            Dim oRng As Object
            Dim sCustomer As String
            Dim patterns As Variant, pattern As Variant
            Dim answer As VbMsgBoxResult

            ' bail out if the preconditions are not right
            If ActiveExplorer.Selection.Count = 0 Then Exit Sub
            If Not (TypeOf ActiveExplorer.Selection.item(1) Is MailItem) Then Exit Sub

            Set olItem = ActiveExplorer.Selection.item(1)
            Set oRng = olItem.GetInspector.WordEditor.Range

            ' add more wildcard patterns in descending order of likelyhood
            patterns = Array("[0-9-]{8;9}", "[A-Z][0-9-]{8;9}")

            For Each pattern In patterns
            oRng.WholeStory
            While oRng.Find.Execute(findText:=pattern, MatchWildcards:=True, MatchWholeWord:=True)
            answer = MsgBox(oRng.Text, vbYesNoCancel + vbQuestion, "Customer Number")
            If answer = vbYes Then
            With New DataObject
            .SetText oRng.Text
            .PutInClipboard
            End With
            Exit For
            ElseIf answer = vbCancel Then
            Exit For
            End If
            Wend
            Next pattern
            End Sub


            Setting variables to Nothing at the end of the function is superfluous.






            share|improve this answer




























              1














              Searches based on wildcards are limited to what wildcards can provide, which is better than nothing, but still not very much.



              Outlook uses Word functions for this, so that the VBA documentation for Word applies. Applicable wildcards themselves are can be seen using the "Special" button in the "Find" dialog (F4 in Outlook), after "use wildcards" has been checked.



              To my knowledge there is no concept of "optional" parts in wildcard searches, which means you need to try more than one wildcard pattern to cover your "sometimes there is a letter in front" case.



              So the general approach, based this knowledge and on your sample code, would be




              • Pick the currently selected MailItem in the ActiveExplorer

              • For each predefined wildcard pattern


                • reset the search range to the whole email

                • execute wildcard search

                • as long as there are search hits


                  • display result, let user pick or cancel the search






              This way multiple patterns can be defined and you have a chance to continue to the next hit if the first hit is a false positive.



              I found the pattern [0-9-]{8;9} plus MatchWholeWord to work reasonably well (blocks of digits and dashes, between 8 or 9 characters long), but real life data often has surprises. You will probably need to add more patterns. Watch out: for me, Outlook wants ; instead of ,. This might be dependent on the system locale, I'm not sure.



              Also I'm not a fan of a "silent" On Error Resume. If there is an error, I prefer to see an error actual message. If there is a condition that can be checked in order to prevent an error, I prefer to check for this condition explicitly. This makes the code more robust and debugging easier. My Sub does not contain an On Error line for that reason.



              In code, this would look like this:



              Sub GetCustomer()
              Dim olItem As Outlook.MailItem
              Dim oRng As Object
              Dim sCustomer As String
              Dim patterns As Variant, pattern As Variant
              Dim answer As VbMsgBoxResult

              ' bail out if the preconditions are not right
              If ActiveExplorer.Selection.Count = 0 Then Exit Sub
              If Not (TypeOf ActiveExplorer.Selection.item(1) Is MailItem) Then Exit Sub

              Set olItem = ActiveExplorer.Selection.item(1)
              Set oRng = olItem.GetInspector.WordEditor.Range

              ' add more wildcard patterns in descending order of likelyhood
              patterns = Array("[0-9-]{8;9}", "[A-Z][0-9-]{8;9}")

              For Each pattern In patterns
              oRng.WholeStory
              While oRng.Find.Execute(findText:=pattern, MatchWildcards:=True, MatchWholeWord:=True)
              answer = MsgBox(oRng.Text, vbYesNoCancel + vbQuestion, "Customer Number")
              If answer = vbYes Then
              With New DataObject
              .SetText oRng.Text
              .PutInClipboard
              End With
              Exit For
              ElseIf answer = vbCancel Then
              Exit For
              End If
              Wend
              Next pattern
              End Sub


              Setting variables to Nothing at the end of the function is superfluous.






              share|improve this answer


























                1












                1








                1







                Searches based on wildcards are limited to what wildcards can provide, which is better than nothing, but still not very much.



                Outlook uses Word functions for this, so that the VBA documentation for Word applies. Applicable wildcards themselves are can be seen using the "Special" button in the "Find" dialog (F4 in Outlook), after "use wildcards" has been checked.



                To my knowledge there is no concept of "optional" parts in wildcard searches, which means you need to try more than one wildcard pattern to cover your "sometimes there is a letter in front" case.



                So the general approach, based this knowledge and on your sample code, would be




                • Pick the currently selected MailItem in the ActiveExplorer

                • For each predefined wildcard pattern


                  • reset the search range to the whole email

                  • execute wildcard search

                  • as long as there are search hits


                    • display result, let user pick or cancel the search






                This way multiple patterns can be defined and you have a chance to continue to the next hit if the first hit is a false positive.



                I found the pattern [0-9-]{8;9} plus MatchWholeWord to work reasonably well (blocks of digits and dashes, between 8 or 9 characters long), but real life data often has surprises. You will probably need to add more patterns. Watch out: for me, Outlook wants ; instead of ,. This might be dependent on the system locale, I'm not sure.



                Also I'm not a fan of a "silent" On Error Resume. If there is an error, I prefer to see an error actual message. If there is a condition that can be checked in order to prevent an error, I prefer to check for this condition explicitly. This makes the code more robust and debugging easier. My Sub does not contain an On Error line for that reason.



                In code, this would look like this:



                Sub GetCustomer()
                Dim olItem As Outlook.MailItem
                Dim oRng As Object
                Dim sCustomer As String
                Dim patterns As Variant, pattern As Variant
                Dim answer As VbMsgBoxResult

                ' bail out if the preconditions are not right
                If ActiveExplorer.Selection.Count = 0 Then Exit Sub
                If Not (TypeOf ActiveExplorer.Selection.item(1) Is MailItem) Then Exit Sub

                Set olItem = ActiveExplorer.Selection.item(1)
                Set oRng = olItem.GetInspector.WordEditor.Range

                ' add more wildcard patterns in descending order of likelyhood
                patterns = Array("[0-9-]{8;9}", "[A-Z][0-9-]{8;9}")

                For Each pattern In patterns
                oRng.WholeStory
                While oRng.Find.Execute(findText:=pattern, MatchWildcards:=True, MatchWholeWord:=True)
                answer = MsgBox(oRng.Text, vbYesNoCancel + vbQuestion, "Customer Number")
                If answer = vbYes Then
                With New DataObject
                .SetText oRng.Text
                .PutInClipboard
                End With
                Exit For
                ElseIf answer = vbCancel Then
                Exit For
                End If
                Wend
                Next pattern
                End Sub


                Setting variables to Nothing at the end of the function is superfluous.






                share|improve this answer













                Searches based on wildcards are limited to what wildcards can provide, which is better than nothing, but still not very much.



                Outlook uses Word functions for this, so that the VBA documentation for Word applies. Applicable wildcards themselves are can be seen using the "Special" button in the "Find" dialog (F4 in Outlook), after "use wildcards" has been checked.



                To my knowledge there is no concept of "optional" parts in wildcard searches, which means you need to try more than one wildcard pattern to cover your "sometimes there is a letter in front" case.



                So the general approach, based this knowledge and on your sample code, would be




                • Pick the currently selected MailItem in the ActiveExplorer

                • For each predefined wildcard pattern


                  • reset the search range to the whole email

                  • execute wildcard search

                  • as long as there are search hits


                    • display result, let user pick or cancel the search






                This way multiple patterns can be defined and you have a chance to continue to the next hit if the first hit is a false positive.



                I found the pattern [0-9-]{8;9} plus MatchWholeWord to work reasonably well (blocks of digits and dashes, between 8 or 9 characters long), but real life data often has surprises. You will probably need to add more patterns. Watch out: for me, Outlook wants ; instead of ,. This might be dependent on the system locale, I'm not sure.



                Also I'm not a fan of a "silent" On Error Resume. If there is an error, I prefer to see an error actual message. If there is a condition that can be checked in order to prevent an error, I prefer to check for this condition explicitly. This makes the code more robust and debugging easier. My Sub does not contain an On Error line for that reason.



                In code, this would look like this:



                Sub GetCustomer()
                Dim olItem As Outlook.MailItem
                Dim oRng As Object
                Dim sCustomer As String
                Dim patterns As Variant, pattern As Variant
                Dim answer As VbMsgBoxResult

                ' bail out if the preconditions are not right
                If ActiveExplorer.Selection.Count = 0 Then Exit Sub
                If Not (TypeOf ActiveExplorer.Selection.item(1) Is MailItem) Then Exit Sub

                Set olItem = ActiveExplorer.Selection.item(1)
                Set oRng = olItem.GetInspector.WordEditor.Range

                ' add more wildcard patterns in descending order of likelyhood
                patterns = Array("[0-9-]{8;9}", "[A-Z][0-9-]{8;9}")

                For Each pattern In patterns
                oRng.WholeStory
                While oRng.Find.Execute(findText:=pattern, MatchWildcards:=True, MatchWholeWord:=True)
                answer = MsgBox(oRng.Text, vbYesNoCancel + vbQuestion, "Customer Number")
                If answer = vbYes Then
                With New DataObject
                .SetText oRng.Text
                .PutInClipboard
                End With
                Exit For
                ElseIf answer = vbCancel Then
                Exit For
                End If
                Wend
                Next pattern
                End Sub


                Setting variables to Nothing at the end of the function is superfluous.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 3 at 18:40









                TomalakTomalak

                261k52434550




                261k52434550
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54026731%2fsearch-currently-viewed-email-for-a-specific-phrase-fetch-a-string-to-copy-to-c%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Monofisismo

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas