Computer Forum Forum Index
Register  FAQ Profile Log in to check your private messages Log in Register 

Need help with macro - trying to keep source formatting in N

 
Post new topic   Reply to topic    Computer Forum Forum Index -> microsoft word vba general
View previous topic :: View next topic  
Author Message
MC
Guest





PostPosted: Fri Dec 21, 2007 8:16 pm    Post subject: Need help with macro - trying to keep source formatting in N Reply with quote

Would there be a way to keep format from source in this algorithm while I
copy selected highlighted text (in green) from source to a new document?

Your input is much appreciated.
Thanks!

-----------------------------------------------------------------
Sub Summarize()
Dim NewDoc As Document, MainDoc As Document, r As Range
If Documents.Count = 0 Then Exit Sub
Set MainDoc = ActiveDocument
Set NewDoc = Documents.Add
MainDoc.Activate
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting

With Selection.Find
..Text = ""
..Forward = True
..Wrap = wdFindContinue
..Format = False
..Highlight = True
Do While .Execute
Set r = NewDoc.Range
r.Collapse wdCollapseEnd
Select Case Selection.Range.HighlightColorIndex

Case wdBrightGreen
r.Collapse wdCollapseEnd
r.InsertAfter Selection.Range.FormattedText
If Selection.Characters.Last.Text <> vbCr Then _
r.InsertAfter vbCr
r.ParagraphFormat.LeftIndent = 18
r.HighlightColorIndex = wdBrightGreen

End Select
Loop


End With
NewDoc.Activate

End Sub
-----------------------------------------------------------------
Back to top
Google
Sponsor





PostPosted: Fri Dec 21, 2007 8:16 pm    Post subject: Advertisement

Back to top
Helmut Weber
Guest





PostPosted: Sat Dec 22, 2007 12:50 pm    Post subject: Re: Need help with macro - trying to keep source formatting Reply with quote

Hi,

see:

http://groups.google.de/group/microsoft.public.word.vba.general/browse_thread/thread/7b3af72e2377de7d/7a789554588cb103?hl=de&lnk=st&q=group%3A*microsoft.public.word%2Cvba.general+author%3AHelmut+author%3AWeber#7a789554588cb103

for how to get text with formatting
from one doc to another without copying anything.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
Back to top
MC
Guest





PostPosted: Sat Dec 22, 2007 7:30 pm    Post subject: Re: Need help with macro - trying to keep source formatting Reply with quote

Thank you for your kind reply. This is tremendously helpful.

Actually, if I could ask you one more question: after summarizing I would
like to specifically compact paragraphs that contain yellow highlighting. I
have a vbs script that compacts all paragraphs in general, how could I modify
it to specifically compact a certain highlight color? Thanks again for your
expert advice.

-------------------------------
Sub CompactParagraph()
'
' CompactParagraph Macro
'
'
For Each Xpara In ActiveDocument.Paragraphs

Xpara.Range.Select
Selection.Characters(Selection.Characters.Count).Delete
Selection.Characters(Selection.Characters.Count).InsertAfter (" ")

Next

End Sub
---------------------------------

Regards,
MC

"Helmut Weber" wrote:

Quote:
Hi,

see:

http://groups.google.de/group/microsoft.public.word.vba.general/browse_thread/thread/7b3af72e2377de7d/7a789554588cb103?hl=de&lnk=st&q=group%3A*microsoft.public.word%2Cvba.general+author%3AHelmut+author%3AWeber#7a789554588cb103

for how to get text with formatting
from one doc to another without copying anything.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
Back to top
Helmut Weber
Guest





PostPosted: Sat Dec 22, 2007 9:11 pm    Post subject: Re: Need help with macro - trying to keep source formatting Reply with quote

Hi MC,

so you want to remove the paragraph mark
from all paragraphs that include some
text highlighted in a certain highlight?

First, not possible at all,
if the last paragaph in the doc contains text highlighted
in that color. You can't delete the last paragraph mark,
if the paragraph contains text, whithout creating a new paragraph,
in a way. I can't explain all details here.

Second, no good idea, as such a macro
would with each run remove another paragraph mark.

You got to be more specific.
Remove highlighting as well?

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
Back to top
MC
Guest





PostPosted: Sun Dec 23, 2007 2:58 am    Post subject: Re: Need help with macro - trying to keep source formatting Reply with quote

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


"Helmut Weber" wrote:

Quote:
Hi MC,

so you want to remove the paragraph mark
from all paragraphs that include some
text highlighted in a certain highlight?

First, not possible at all,
if the last paragaph in the doc contains text highlighted
in that color. You can't delete the last paragraph mark,
if the paragraph contains text, whithout creating a new paragraph,
in a way. I can't explain all details here.

Second, no good idea, as such a macro
would with each run remove another paragraph mark.

You got to be more specific.
Remove highlighting as well?

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
Back to top
Helmut Weber
Guest





PostPosted: Sun Dec 23, 2007 12:00 pm    Post subject: Re: Need help with macro - trying to keep source formatting Reply with quote

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
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Computer Forum Forum Index -> microsoft word vba general All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Computer Forum