
Signature
.NET: It's About Trust!
http://vfred.mvps.org
Thanks! Works like a charm. ed
>> Is there a function that counts the number of times a particular
>> character
[quoted text clipped - 11 lines]
> ?ubound(split("abcabcabcab", "c"))
> 3
Karl (or others):
I am trying to count "forward slashes". "/"
The routine you suggested works perfectly in Word2003. And it works
perfectly in Word2007 if there are no images. But if there are images within
the selected text, the images get counted as a slash, messing up the count.
Is there another technique? (Is this a bug in Word2007)?
Example: Texttexttext/(image1)Texttexttext2/(image2)Texttexttext3
Ed (in Virginia)
>> Is there a function that counts the number of times a particular
>> character
[quoted text clipped - 11 lines]
> ?ubound(split("abcabcabcab", "c"))
> 3
Jean-Guy Marcil - 14 Mar 2008 15:08 GMT
> Karl (or others):
>
[quoted text clipped - 6 lines]
>
> Example: Texttexttext/(image1)Texttexttext2/(image2)Texttexttext3
Try this:
Dim rgeFind As Range
Dim lngRgeEnd As Long
Dim lngFindCount As Long
Set rgeFind = Selection.Range
lngRgeEnd = rgeFind.End
lngFindCount = 0
Do While rgeFind.Find.Execute(FindText:="\", Wrap:=wdFindStop)
lngFindCount = lngFindCount + 1
Set rgeFind = ActiveDocument.Range(rgeFind.End, lngRgeEnd)
Loop
MsgBox "The target character was found " & lngFindCount & " times."
Roy - 17 Mar 2008 14:43 GMT
Sorry, but same error. Apparently the XML coding is sticking into the mix
the very character that I am trying to count. Works fine in XP and 2003
documents. Fails with XML (2007) documents.
>> Karl (or others):
>>
[quoted text clipped - 25 lines]
>
> MsgBox "The target character was found " & lngFindCount & " times."
Jean-Guy Marcil - 17 Mar 2008 15:33 GMT
> Sorry, but same error. Apparently the XML coding is sticking into the mix
> the very character that I am trying to count. Works fine in XP and 2003
> documents. Fails with XML (2007) documents.
Sorry, but I can't test my code as I do not have access to 2007 right now.
But, for others who can test code with 2007, when you state "but same
error", are you still referring to the fact that the images are being counted
as a slash, thus throwing off the count? Or is there a new error that came up
when you tried it with XML documents? (In your previous post you mentioned
images, now you are writing about XML documents).
You could add code to count the number of inlineshapes in the range and then
subtract that amount from the total my code (or Karls's code) returns.
Karl E. Peterson - 19 Mar 2008 19:14 GMT
> Karl (or others):
>
[quoted text clipped - 4 lines]
> the selected text, the images get counted as a slash, messing up the count.
> Is there another technique? (Is this a bug in Word2007)?
As I suggested, you'll need to reduce the selection to *text*, for my trick to work.
That's an object model issue; one I'm not all that familiar with. There's gotta be
some simple method, though. The images, obviously, are not text.

Signature
.NET: It's About Trust!
http://vfred.mvps.org
Klaus Linke - 19 Mar 2008 21:28 GMT
> (Is this a bug in Word2007)?
Yes, and a pretty silly one, given that there had been wishes in previous
versions that, instead of Ascii 1, a more sensible Unicode character might
be used ... private, or U+FFFC = "object replacement character", or
whatever... but *not* a "/".
Regards,
Klaus