gul791
08-02-2004, 09:49 AM
How can i filter text in microsoft word that has a different format. I want to list all text chunks that has different format along with these format properties (font, size, color).
For exaple for the following
"This is a Example. This example text has different text formats"
and the output should be
This is a Exa
mple
This
exa
mple
text has different text format
regards
Atif
Wamphyri
08-03-2004, 07:23 AM
Okay, right off the bat I can think of a couple ways that should work, but I am wondering about how large a piece of text are we talking about in a real situation?
gul791
08-03-2004, 07:39 AM
Okay, right off the bat I can think of a couple ways that should work, but I am wondering about how large a piece of text are we talking about in a real situation?
Actullay I want to convert some nonunicode text to unicode fonts. For that I have to select/filter some nonunicode fonts text with format detail.
Wamphyri
08-03-2004, 01:53 PM
This code should work assuming I've remembered the correct values for color and size being not all equal. (I don't have word on this computer so it does make for a slightly more difficult challenge! ;) )
Since this is a .Net question you'll have to convert it to work with .Net but I'll leave that up to you.
Dim oRng As Word.Range 'Main range
Dim oFRng As Word.Range 'Found the same range
Dim lEnd As Long
Dim lStart As Long
Dim i As Long
Set oFRng = ActiveDocument.Content
Set oRng = ActiveDocument.Content
MsgBox oRng.Font.Color '9999999 means not all the same
MsgBox oRng.Font.Size '9999999 means not all the same
MsgBox oRng.Font.Name '"" means not all the same
lEnd = oRng.End
lStart = oRng.Start
For i = lStart To lEnd
oRng.End = i
'If not all the same color
If oRng.Font.Color = 9999999 Then
bdiff = True
End If
'If not all the same size
If oRng.Font.Size = 9999999 Then
bdiff = True
End If
'If not all the same font
If oRng.Font.Name = "" Then
bdiff = True
End If
'If there is any differences in range
If bdiff Then
oFRng.Start = oRng.Start
oFRng.End = i - 1
oRng.Start = i - 1
Debug.Print oFRng.Text
bdiff = False
End If
Next
'Oops I forgot to add this line to get the last group (Or in the case that
'everything is the same)
Debug.Print oRng.Text
gul791
08-04-2004, 09:08 AM
Thanks for you help. Its a little bit slow, but i think we have no other solution.
Wamphyri
08-05-2004, 11:51 AM
Yeah, I knew it would be slow. The only other thing I can think of to make it faster is using the find method and dynamically changing the font, size, and color to the properties of the first character of the remaining range. (As above you'd shorten the range as you found chunks of text that are the same.) Depending on how long your chunks of text are the speed improvement could be quite good. Larger chunks = better speed improvement.
Wamphyri
08-05-2004, 01:50 PM
Thanks for you help. Its a little bit slow, but i think we have no other solution.
We always have other solutions. I think this version should be quicker.
Dim oRng As Word.Range 'Main range
Dim oFRng As Word.Range 'Find Range like this one
Dim lEnd As Long
Set oFRng = ActiveDocument.Range(0, 1)
Set oRng = ActiveDocument.Content
lEnd = oRng.End
Do
With oRng.Find
.ClearFormatting
.Font.Color = oFRng.Font.Color
.Font.Size = oFRng.Font.Size
.Font.Name = oFRng.Font.Name
.Execute Wrap:=wdFindStop
End With
Debug.Print oRng.Text
If oRng.End = lEnd Then
Exit Do
End If
oRng.Start = oRng.End
oRng.End = lEnd
oFRng.Start = oRng.Start
oFRng.End = oRng.Start
Loop