By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,607 Members | 1,972 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,607 IT Pros & Developers. It's quick & easy.

A Macro to select every 3rd word after selection

P: 8
Hi
I need a code for a macro to select every 3rd word after selection.
Jun 28 '10 #1
Share this Question
Share on Google+
7 Replies


ADezii
Expert 5K+
P: 8,702
@alphanj
Have no idea as to what you are requesting, kindly be more specific, and post concrete examples.
Jun 28 '10 #2

100+
P: 255
So you want something like this?

Input:
I am human I am human I am human

Output:
human human human
Jun 28 '10 #3

P: 8
@colintis
@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
Jun 29 '10 #4

NeoPa
Expert Mod 15k+
P: 31,769
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).
Jun 29 '10 #5

ADezii
Expert 5K+
P: 8,702
@alphanj
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:
Expand|Select|Wrap|Line Numbers
  1. Dim strTestString As String
  2. Dim varSplit As Variant
  3. Dim intCounter As Integer
  4. Dim strBuild As String
  5.  
  6. strTestString = "She sells sea shells at the sea shore on a windy day"
  7.  
  8. varSplit = Split(strTestString, " ")
  9.  
  10. For intCounter = LBound(varSplit) To UBound(varSplit)
  11.   If (intCounter + 1) Mod 3 = 0 Then
  12.     strBuild = strBuild & " " & UCase(varSplit(intCounter))
  13.   Else
  14.     strBuild = strBuild & " " & varSplit(intCounter)
  15.   End If
  16. Next
  17.  
  18. Debug.Print Trim(strBuild)
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. She sells SEA shells at THE sea shore ON a windy DAY
Jun 29 '10 #6

NeoPa
Expert Mod 15k+
P: 31,769
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.
Jun 29 '10 #7

ADezii
Expert 5K+
P: 8,702
@NeoPa
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.
Jun 29 '10 #8

Post your reply

Sign in to post your reply or Sign up for a free account.