Re: Finding multiple occurrences of character in word document
- From: "Klaus Linke" <info@xxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 4 Apr 2006 00:37:38 +0200
Oh yes. Sorry, didn't read carefully.
You could also loop the sentences (like you did, or using "For Each"), read
the text into a string, and do a Split with the comma as a delimiter.
The upper bound would give you the number of commas.
Dim rngSentence As Range
For Each rngSentence In ActiveDocument.Sentences
Debug.Print UBound(Split(rngSentence.Text, ","))
Next rngSentence
Klaus
"Greg Maxey" <gmaxey@xxxxxxxxxxxxxxxxxxx> wrote:
Klaus,
I might have it wrong, but I think he is looking for two commas occurring
anywhere in the sentence and not just adjacent to each other.
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
Klaus Linke wrote:
Hi TazCoder,
A simple and fast way would likely be a wildcard search for (,){2}
The macro recorder should give you the code.
If you want to also find triple, quadruple... occurrences, the
wildcard search for that would be (,){2,}
(if the field separator in your Windows installation is a comma).
Greetings,
Klaus
"TazCoder" <mlbtaz@xxxxxxx> wrote:
I have been writing a large macro and the final step is to find
multiple occurrences' of a specific character in one sentence. The
algorithm must:
Search every sentence in the word document, find any sentence that
has more then two (commas, or any other specific character), and
highlight the two of them.
I know the basic idea behind the algorithm and I know how to
implement it in C/C++/Java but not in VBA. I need to load each
sentence (searching for the period) into a string. In this string
look for a comma, remember the index and increment the counter by
one, continue to search for another comma. If another one is not
found I am done, if another one is found, mark that position, and
highlight the two positions.
The problem I have is with the actual coding. How can I go about
doing this?
How can I load each specific sentence into a string? (note the
sentences only end in periods, which makes is slightly less
complicated.)
How can I find the position of each comma within that string?
Once I have those two problems solved, the rest is easy.
Thanks.
.
- References:
- Finding multiple occurrences of character in word document
- From: TazCoder
- Re: Finding multiple occurrences of character in word document
- From: Klaus Linke
- Re: Finding multiple occurrences of character in word document
- From: Greg Maxey
- Finding multiple occurrences of character in word document
- Prev by Date: Re: Importing Outlook Contacts data into Word VBA?
- Next by Date: Getting Range of a Comment?
- Previous by thread: Re: Finding multiple occurrences of character in word document
- Next by thread: Re: Finding multiple occurrences of character in word document
- Index(es):
Relevant Pages
|