Hi Mr Weber,
Thanks for your reply again.
Essentially, What I do is the following: as I read a text, I highlight the
titles or subtitles in a different color (i.e. green or gray) while the
paragraph under each title, I highlight it in yellow.
Currently, with the script, copied texts in the Target document end up
fragmented..each separated by paragraph marks
(or separated by Linebreaks if I read documents in columns that have been
converted from pdf).
What would really help is to have a macro (even if it means a second macro)
that can recognize copied text in the target new document that are
highlighted in yellow and specifically collapse those together (and
separated by a space) without collapsing the subtitles with them or other
sections of yellow-highlighted text that belong under other subtitles.... in
essence too, I would like to join all yellow highlighted text flanked by
green-highlighted subtitles, section by section.
Would this be possible?
I know that when the subtitles have paragraph marks after them and the body
paragraphs have linebreaks and no paragraph marks, one can specifically
delete those linebreaks... but when there are paragraph marks all over the
place instead, it becomes more of a challenge... but I suspect it might still
be possible to join text as long as there are other markers (in this case
subtitles highlighted in different colors) that flank them.
Alternative solution would be a macro that can 'replace every paragraph mark
that follow a yellow-hilighted text with a linebreak' and then a second macro
to delete linebreaks specifically. Would this be an easier approach?
Any thoughts on these two approaches?
Thanks again for your expert guidance.
cheers,
MC
> Hi MC,
>
[quoted text clipped - 21 lines]
>
> Vista Small Business, Office XP
Helmut Weber - 23 Dec 2007 12:00 GMT
Hi,
hmm... I'd prefer a third approach.
As you are speaking about titles, subtitles
and bodytext, apparingly, applying paragraph styles
would be best.
Create the three styles, and apply e.g. style "bodytext"
to every paragraph, which contains yellow highlighting, like that:
Sub Test0884a()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Highlight = True
While .Execute
rDcm.Select ' for testing
Stop ' for testing
If rDcm.HighlightColorIndex = wdYellow Then
rDcm.Style = "Bodytext"
End If
Wend
End With
End Sub
Sub Test0884b()
Dim rDcm As Range
Dim rTmp As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Style = "Bodytext"
While .Execute
rDcm.Select ' for testing
Stop ' for testing
For Each rTmp In rDcm.Characters
If rTmp.Text = Chr(11) Then
rTmp.Text = " "
End If
Next
Wend
End With
End Sub
Sub Test0884c()
' join consecutive bodytext paragraphs
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Style = "Bodytext"
While .Execute
rDcm.Select ' for testing
Stop ' for testing
If rDcm.Paragraphs(1).Next.Style = "Bodytext" Then
rDcm.Characters.Last = " "
End If
Wend
End With
End Sub
Which is far from being perfect,
but preserves the highlighting,
which some other simpler methods don't do.
Of course, all could be combined into one sub.
An error will occur, if there is no next paragraph.
There are methods to prevent that, as well.
See above: "merging cells using VB"
on how to check whether an object is nothing...
But, IMHO, you are looking for a working solution,
rather than for perfection.
--
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Vista Small Business, Office XP