How to change the delimiter?

K

khairule

Hi,

I am using Word.Application.Document.Sentences to get all sentences in
a word document. By default, the VBA would return sentences delimited
by full stop. How could I change it to look for other delimiters, such
as a comma, or even custom define it?

For example, these are 2 sentences in a paragraph:

{##1##}The brown fox jumps over the lazy dog. {/##1##}{##2##}The brown
fox jumps over the lazy dog. {/##2##}

If I use Word.Application.Document.Sentences in a loop, it would return
me 3 lines:
line 1: {##1##}The brown fox jumps over the lazy dog.
line 2: {/##1##}{##2##}The brown fox jumps over the lazy dog.
line 3: {/##2##}

What I need is to have only these 2 sentences:
line 1:{##1##}The brown fox jumps over the lazy dog. {/##1##}
line 2:{##2##}The brown fox jumps over the lazy dog. {/##2##}

Please help. Thank you in advance.
 
J

Jonathan West

Hi khairule

Short answer is that you can't do this directly. The best thing to do is to
load the entire text of the document into a string variable, and then
process the string in whatever way you want. You can get the entire
unformatted text of the document into a string by assigning the
ActiveDocument.Content.Text property to a string.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 

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