Using FormattedText did however resolve a problem I was having getting the
macro to format the text correctly in a table cell. I don't know why I
didn't consider it earlier
Using the table does seem noticably faster.
Can you tell it's the slack period twixt Christmas and New Year?
Dim oRng, oNrng As Range
Dim oSource, oDoc As Document
Dim oTable As Table
Dim iRow, iPage, ILen As Integer
Dim iPara, iIst, iLast As Integer
Dim sFont, SComp, sNext, sWords As String
Dim sColor As WdColor
Set oSource = ActiveDocument
Set oDoc = Documents.Add
Set oTable = oDoc.Tables.Add(oDoc.Range, 2, 4)
With oTable
.Cell(1, 1).Range.Text = "Highlighted Text"
.Cell(1, 2).Range.Text = "Page"
.Cell(1, 3).Range.Text = "Font"
.Cell(1, 4).Range.Text = "Comments"
With .Rows(1).Range
.ParagraphFormat.Alignment = _
wdAlignParagraphCenter
.Font.name = "Arial"
.Font.Size = "12"
.Bold = True
End With
End With
oSource.Activate
With Selection
.HomeKey Unit:=wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Highlight = True
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
Do While .Execute = True
Set oRng = Selection.Range
With oRng
iIst = .Start - .Words.First.Start + 1
iLast = .Words.Last.End - .End
sNext = .Next.Characters(1)
'sColor = .HighlightColorIndex
If .Start <> .Words.First.Start Or _
.End <> .Words.Last.End - 1 And _
sNext <> "" Then
Select Case sNext
Case ",", ".", "?", "!", ":", ";"
SComp = ""
iLast = iLast +1
Case Else
SComp = "Partlyhighlighted"
End Select
Else
SComp = ""
End If
.Start = .Words.First.Start
.End = .Words.Last.End
If .Characters.Last = Chr(32) Then
.End = .Words.Last.End - 1
End If
sFont = .Font.name
If Len(sFont) < 1 Then sFont = "Mixed fonts detected"
iPage = .Information(wdActiveEndPageNumber)
iRow = oTable.Rows.Count
oTable.Cell(iRow, 1).Range.FormattedText =
oRng.FormattedText
oTable.Cell(iRow, 2).Range.Text = iPage
oTable.Cell(iRow, 2).Range.ParagraphFormat.Alignment _
= wdAlignParagraphCenter
oTable.Cell(iRow, 3).Range.Text = sFont
oTable.Cell(iRow, 4).Range.Text = SComp
oTable.Rows.Add
End With
Loop
End With
End With
oTable.Rows.Last.Delete
oDoc.Activate
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
- Zitierten Text anzeigen -