How to find a soft hyphen

L

LC

I use the Word Selection object to "walk" every character of a text.
This works well until there is a soft hyphen inserted by Word for
breaking up a long word. The Selection object just doesn't see the soft
hyphen. I tried all sorts of objects like Range, Word, Character and
Find but nothing worked. Anyone knows how to "see" in Word VBA a soft
hyphen?

Thanks in advance
LC
 
M

Marco Pagliero

LC said:
I use the Word Selection object to "walk" every character of a text.
This works well until there is a soft hyphen inserted by Word for
breaking up a long word. The Selection object just doesn't see the soft
hyphen. I tried all sorts of objects like Range, Word, Character and
Find but nothing worked. Anyone knows how to "see" in Word VBA a soft
hyphen?

It seems that soft hyphens don't actually exist: they are not contained
in the selection and they are also not saved in the document file.
Maybe Word adds them on-the-fly when displaying the page?

On the other hand, why do you need to see them in the first place?
Maybe we can find a solution for _this_ special problem.

Greetings

Marco P
 
L

LC

I'm writing a simple device-independent text-only EPS driver in word
VBA. So far I've got everything I need except the soft hyphenation. I
also suspect the soft hyphen is not stored anywhere. I thought of
marking a word and then walk each letter of the word checking for its
vertical position to detect a break but there must be a more elegant
solution.
 
J

Jezebel

You can infer the presence of soft hyphens by walking the displayed lines of
the document --

ActiveDocument.ActivePanes.Pages(1).Rectangles(1).Lines(1).Range

Compare each line range with the corresponding sub-range of the original in
the document body: if the last 'word' in the line is only part of a word in
the original, then a hyphen has been inserted. Conversely, if it IS a full
word, and it's not the final word of the paragraph, then the following
space(s) will have been omitted.

It sure ain't elegant, but faute de mieux.
 
L

LC

Thank you for responding. That gave me an idea. I walk a line of text,
character by character. When I see the last character is a letter, I do
a MoveRight wdWord, wdExtend and then count the number of characters
selected. If more than one, I assume there is a soft hyphen. It is
still not the "elegant" solution I was hoping for for it might fail in
some strange cases but it works reasonably well enough for me, for now
until I'll find a better solution.

Thanks
LC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top