A Macro to select every 3rd word after selection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alphanj
    New Member
    • Jun 2010
    • 8

    A Macro to select every 3rd word after selection

    Hi
    I need a code for a macro to select every 3rd word after selection.
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by alphanj
    Hi
    I need a code for a macro to select every 3rd word after selection.
    Have no idea as to what you are requesting, kindly be more specific, and post concrete examples.

    Comment

    • colintis
      Contributor
      • Mar 2010
      • 255

      #3
      So you want something like this?

      Input:
      I am human I am human I am human

      Output:
      human human human

      Comment

      • alphanj
        New Member
        • Jun 2010
        • 8

        #4
        Originally posted by colintis
        So you want something like this?

        Input:
        I am human I am human I am human

        Output:
        human human human
        @colintis
        some thing like that, but without output,
        I want macro to find 3rd word, change its format, go to next 3rd word change the format again until the end of the document.

        Like this:
        I am human I am human I am human

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32634

          #5
          Is this a Microsoft Word related question by any chance? It doesn't help to leave out so much important information when posting a question (in a predominantly Access forum).

          Comment

          • ADezii
            Recognized Expert Expert
            • Apr 2006
            • 8834

            #6
            Originally posted by alphanj
            @colintis
            some thing like that, but without output,
            I want macro to find 3rd word, change its format, go to next 3rd word change the format again until the end of the document.

            Like this:
            I am human I am human I am human
            Like NeoPa, I feel as though this may be a Word question. In any event, I wrote comparable code that will also work in Word. In this case each 3rd Word is formatted in Upper Case:
            Code:
            Dim strTestString As String
            Dim varSplit As Variant
            Dim intCounter As Integer
            Dim strBuild As String
            
            strTestString = "She sells sea shells at the sea shore on a windy day"
            
            varSplit = Split(strTestString, " ")
            
            For intCounter = LBound(varSplit) To UBound(varSplit)
              If (intCounter + 1) Mod 3 = 0 Then
                strBuild = strBuild & " " & UCase(varSplit(intCounter))
              Else
                strBuild = strBuild & " " & varSplit(intCounter)
              End If
            Next
            
            Debug.Print Trim(strBuild)
            OUTPUT:
            Code:
            She sells SEA shells at THE sea shore ON a windy DAY

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32634

              #7
              It's nevertheless an important question my friend, as Word has built-in objects and collections for things like words and paragraphs etc. It's not a good idea to reinvent the wheel. It introduces too many complications, and issues of compatibility etc. It's really down to the OP to make the question clear in the first place, or at least to respond intelligently to prompts.

              To be clear, this is not a critique of your code in any way.

              Comment

              • ADezii
                Recognized Expert Expert
                • Apr 2006
                • 8834

                #8
                Originally posted by NeoPa
                It's nevertheless an important question my friend, as Word has built-in objects and collections for things like words and paragraphs etc. It's not a good idea to reinvent the wheel. It introduces too many complications, and issues of compatibility etc. It's really down to the OP to make the question clear in the first place, or at least to respond intelligently to prompts.

                To be clear, this is not a critique of your code in any way.
                You are, of course, 100% correct. Just meant to be a Pointer in hopefully the right direction, since at least the Split() Function is supported in Word.

                Comment

                Working...