For example, if I set the selection range to
ActiveDocument.Range([count] - 1, [count])
... and look at the selection on-screen, it will not be the last character
in the document.
Is this a known issue? Is there an easy command to simply remove all
hyperlinks in a document, accomplishing the same thing as right-clicking and
selecting "Remove Hyperlink"?
Dim charcount As Long
Dim i As Long
charcount = 0
With ActiveDocument
For i = 1 To .Fields.Count
charcount = charcount + .Fields(i).Code.Characters.Count
Next i
charcount = charcount + ActiveDocument.Characters.Count
End With
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"da9ve" <da...@discussions.microsoft.com> wrote in message
news:163788B3-9825-4521...@microsoft.com...
I was gong to muse that it might be some extra hidden html that doesn't get
caught as a field, since some of the text in my test document was pasted in
from a web page,.... but on further tweaking, when I simply Remove both the
hyperlinks, the counts come out perfectly consistent, so I'm convinced that
it's something peculiar to the hyperlink fields themselves. What's the deal
with those funky outlined { } braces that delimit the field?
da9ve
What exactly do you want to achieve?
--
Enjoy,
Tony
"da9ve" <da...@discussions.microsoft.com> wrote in message
news:F1D18A8C-94B6-433C...@microsoft.com...
>A specific example. A hyperlink with the field codes toggled looks like:
>
> {HYPERLINK
> "http://www.word.mvps.org/FAQs/MacrosVBA/FindReplaceSymbols.htm"
> \t "winout"}
>
> (... of course with the funky special { } braces).
>
> The characters in the link text itself, in this case:
>
> http://www.word.mvps.org/FAQs/MacrosVBA/FindReplaceSymbols.htm
>
> ... are simply omitted from the count in ActiveDocument.Characters.Count.
Thanks for any clues.
da9ve
"Tony Jollans" wrote:
> .
>
Dim charcount As Long
Dim i As Long
charcount = 0
With ActiveDocument
For i = 1 To .Fields.Count
charcount = charcount + .Fields(i).Code.Characters.Count + 2
Next i
charcount = charcount + ActiveDocument.Characters.Count
End With
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"da9ve" <da...@discussions.microsoft.com> wrote in message
news:BC85372E-BC5D-4558...@microsoft.com...
What, exactly, is 'this'. There may be a better way to do whatever it is
that you are trying to do,
--
Enjoy,
Tony
"da9ve" <da...@discussions.microsoft.com> wrote in message
news:7A9BB884-1693-4A3C...@microsoft.com...
"Tony Jollans" wrote:
> > ... and just don't have the
> > vocabulary yet to know how to do this, though.
>
> What, exactly, is 'this'. There may be a better way to do whatever it is
> that you are trying to do,
The specific "this" I was referring to is 'capturing and handling an error
condition that I would expect to be returned if I try to select a character
using a numerical range that extends past the end of the document.' Being
able to do that would get me away from even bothering with calculating the
total number of characters in the document, which, as we've figured out
elsewhere in this thread, has to include counts for characters in fields plus
field delimiters; and it would still ensure that every character in the
document would get checked.
The bigger "this" that's the purpose of this macro - the 'check' that it's
doing on every character - involves ferreting out every use of Symbol font -
whether as plain formatted Symbol font (easy) or alternately created by the
Insert Symbol tool with Symbol font selected. As I learned in some other
threads specific to that font, it seems to be treated in very unusual and
special ways, and the logic to find it had to include another method besides
just a simple global Find/Replace on Symbol as the font name. (There's also
some logic that goes after a couple specific troublesome Unicode ranges, but
that part was pretty straight-forward.)
I'm satisfied with the logic that others supplied in those other threads
around the Symbol font thing, and that part of the macro works fine. So I'm
really only pursuing obviating the character count complexity.
thanks!
da9ve
"Doug Robbins - Word MVP" wrote:
> The field delimiters are probably not counted, as the .Code.Text of the
> field just returns the text inside them. You probably need to use:
>
> Dim charcount As Long
> Dim i As Long
> charcount = 0
> With ActiveDocument
> For i = 1 To .Fields.Count
> charcount = charcount + .Fields(i).Code.Characters.Count + 2
> Next i
> charcount = charcount + ActiveDocument.Characters.Count
> End With
Yep, I eventually arrived at that myself, based on the margin still left
over at the end when the macro finishes running. That works pretty well for
the case where all the fields are toggled to not show the field codes, but
when any of them are toggled to SHOW field codes, the counts change in ways I
haven't fully figured out yet. But expecting fields to be toggled to hide
field codes is a very reasonable assumption, so I'm going with it for now.
gracias,
da9ve
--
Enjoy,
Tony
"da9ve" <da...@discussions.microsoft.com> wrote in message
news:732928D1-E29B-4740...@microsoft.com...
if I try to select a character using a numerical range that extends past the
end of the document.'
How can anything be past the end of the document??
da9ve wrote:
>> The field delimiters are probably not counted, as the .Code.Text of the
>> field just returns the text inside them. You probably need to use:
>[quoted text clipped - 8 lines]
>> charcount = charcount + ActiveDocument.Characters.Count
>> End With
>
>Yep, I eventually arrived at that myself, based on the margin still left
>over at the end when the macro finishes running. That works pretty well for
>the case where all the fields are toggled to not show the field codes, but
>when any of them are toggled to SHOW field codes, the counts change in ways I
>haven't fully figured out yet. But expecting fields to be toggled to hide
>field codes is a very reasonable assumption, so I'm going with it for now.
>
>gracias,
>da9ve
--
Gerry
Message posted via http://www.officekb.com
"Fumei2 via OfficeKB.com" wrote:
> I am still trying to get my head around:
>
> if I try to select a character using a numerical range that extends past the
> end of the document.'
>
> How can anything be past the end of the document??
>
It can't, and that's my point. The existing logic in the macro leads me to
step through the document, character by character, using:
ActiveDocument.Range(i,i+1).Select
...and incrementing i. When i+1 happens to exceed the location of the last
character in the document, I want to be able to just handle the error
condition that arises, but I flat-out don't know enough VBA to do that. It
seems like this should be a really easy question. What I expect to be able
to do would be something like:
On Error (*some unknown-to-me error code resulting from the above expression
crashing up against the end of the document*) Exit Do
da9ve
ActiveDocument.Content.End gives the same number as the more complicated
method of adding ActiveDocument.Characters.Count PLUS the number of
characters in all fields, PLUS 3 "overhead" characters for each field (which
I determined experimentally), AND it gives a valid, usable number whether the
state of the fields is toggled on or off - which the adding method does not
(also determined experimentally).
So, muchas gracias.
da9ve
"Tony Jollans" wrote:
> .
>