Group:  Microsoft Word ยป microsoft.public.word.oleinterop
Thread: Can I search formatted text?

Geek News

Can I search formatted text?
tutu 10/9/2008 1:49:00 AM
I'm writing an app with VSTO&PIA to parse text with specific format, such as
"Heading2","Bold",red color,etc. In MSDN, a simple string replacement program
looks like this:
object replaceAll = Word.WdReplace.wdReplaceAll;
object missing = Type.Missing;

app.Selection.Find.ClearFormatting();
app.Selection.Find.Text = orig.ToString();

app.Selection.Find.Replacement.ClearFormatting();
app.Selection.Find.Replacement.Text = newstr.ToString();

app.Selection.Find.Execute(
ref orig, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref newstr, ref replaceAll, ref missing,
ref missing, ref missing, ref missing);
Note that both in Find and Replacement, it uses "ClearFormatting()" method.
So is it possible to search formatted text?
Or is there any other ways to parse formatted text from WORD?
Re: Can I search formatted text?
"Doug Robbins - Word MVP" <dkr[ at ]REMOVECAPSmvps.org> 10/9/2008 3:43:41 AM
The ClearFormatting just refers to the search function itself and is used to
remove any formatting attribute that might have been the target of a prior
search.

It has nothing to do with the formatting of the text that is being searched.
For example, the function will find text that is formatted red just as well
as text that is formatted black if the ClearFormatting switch had been set.

--
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

"tutu" <tutu[ at ]discussions.microsoft.com> wrote in message
news:CD7C61B2-6FAC-407A-BE78-3C312AF6D78D[ at ]microsoft.com...
[Quoted Text]
> I'm writing an app with VSTO&PIA to parse text with specific format, such
> as
> "Heading2","Bold",red color,etc. In MSDN, a simple string replacement
> program
> looks like this:
> object replaceAll = Word.WdReplace.wdReplaceAll;
> object missing = Type.Missing;
>
> app.Selection.Find.ClearFormatting();
> app.Selection.Find.Text = orig.ToString();
>
> app.Selection.Find.Replacement.ClearFormatting();
> app.Selection.Find.Replacement.Text = newstr.ToString();
>
> app.Selection.Find.Execute(
> ref orig, ref missing, ref missing, ref missing,
> ref missing, ref missing, ref missing, ref missing,
> ref missing, ref newstr, ref replaceAll, ref missing,
> ref missing, ref missing, ref missing);
> Note that both in Find and Replacement, it uses "ClearFormatting()"
> method.
> So is it possible to search formatted text?
> Or is there any other ways to parse formatted text from WORD?


Re: Can I search formatted text?
tutu 10/9/2008 4:23:01 AM
Well,ok. But leave this method beside, can I search formatted text like red
color text? I've tried this:
object replaceAll = Word.WdReplace.wdReplaceAll;
object missing = Type.Missing;
object format=Word.WdColor.wdColorBlack;

app.Selection.Find.Text = orig.ToString();

app.Selection.Find.Replacement.Text = newstr.ToString();

app.Selection.Find.Execute(
ref orig, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref format, ref newstr, ref replaceAll, ref missing,
ref missing, ref missing, ref missing);

But it didn't not seem to work.
Re: Can I search formatted text?
"Doug Robbins - Word MVP" <dkr[ at ]REMOVECAPSmvps.org> 10/9/2008 9:59:52 AM
Seems to me that if you wanted to find text that was formatted Red, you
should not be using

object format=Word.WdColor.wdColorBlack

--
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

"tutu" <tutu[ at ]discussions.microsoft.com> wrote in message
news:BAF97E78-5130-433B-8BA0-E4117736D25F[ at ]microsoft.com...
[Quoted Text]
> Well,ok. But leave this method beside, can I search formatted text like
> red
> color text? I've tried this:
> object replaceAll = Word.WdReplace.wdReplaceAll;
> object missing = Type.Missing;
> object format=Word.WdColor.wdColorBlack;
>
> app.Selection.Find.Text = orig.ToString();
>
> app.Selection.Find.Replacement.Text = newstr.ToString();
>
> app.Selection.Find.Execute(
> ref orig, ref missing, ref missing, ref missing,
> ref missing, ref missing, ref missing, ref missing,
> ref format, ref newstr, ref replaceAll, ref missing,
> ref missing, ref missing, ref missing);
>
> But it didn't not seem to work.


Re: Can I search formatted text?
tutu 10/9/2008 11:33:00 AM
So is there a way to do this?

"Doug Robbins - Word MVP" wrote:

[Quoted Text]
> Seems to me that if you wanted to find text that was formatted Red, you
> should not be using
>
> object format=Word.WdColor.wdColorBlack
>
> --
> 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
>
> "tutu" <tutu[ at ]discussions.microsoft.com> wrote in message
> news:BAF97E78-5130-433B-8BA0-E4117736D25F[ at ]microsoft.com...
> > Well,ok. But leave this method beside, can I search formatted text like
> > red
> > color text? I've tried this:
> > object replaceAll = Word.WdReplace.wdReplaceAll;
> > object missing = Type.Missing;
> > object format=Word.WdColor.wdColorBlack;
> >
> > app.Selection.Find.Text = orig.ToString();
> >
> > app.Selection.Find.Replacement.Text = newstr.ToString();
> >
> > app.Selection.Find.Execute(
> > ref orig, ref missing, ref missing, ref missing,
> > ref missing, ref missing, ref missing, ref missing,
> > ref format, ref newstr, ref replaceAll, ref missing,
> > ref missing, ref missing, ref missing);
> >
> > But it didn't not seem to work.
>
>
>
Re: Can I search formatted text?
"Doug Robbins - Word MVP" <dkr[ at ]REMOVECAPSmvps.org> 10/9/2008 9:47:08 PM
Selection.Find.ClearFormatting
Selection.Find.Font.Color = wdColorRed
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute


--
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

"tutu" <tutu[ at ]discussions.microsoft.com> wrote in message
news:96E20444-DF91-4583-BE28-50FE932E6A48[ at ]microsoft.com...
[Quoted Text]
> So is there a way to do this?
>
> "Doug Robbins - Word MVP" wrote:
>
>> Seems to me that if you wanted to find text that was formatted Red, you
>> should not be using
>>
>> object format=Word.WdColor.wdColorBlack
>>
>> --
>> 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
>>
>> "tutu" <tutu[ at ]discussions.microsoft.com> wrote in message
>> news:BAF97E78-5130-433B-8BA0-E4117736D25F[ at ]microsoft.com...
>> > Well,ok. But leave this method beside, can I search formatted text like
>> > red
>> > color text? I've tried this:
>> > object replaceAll = Word.WdReplace.wdReplaceAll;
>> > object missing = Type.Missing;
>> > object format=Word.WdColor.wdColorBlack;
>> >
>> > app.Selection.Find.Text = orig.ToString();
>> >
>> > app.Selection.Find.Replacement.Text = newstr.ToString();
>> >
>> > app.Selection.Find.Execute(
>> > ref orig, ref missing, ref missing, ref missing,
>> > ref missing, ref missing, ref missing, ref missing,
>> > ref format, ref newstr, ref replaceAll, ref missing,
>> > ref missing, ref missing, ref missing);
>> >
>> > But it didn't not seem to work.
>>
>>
>>


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net