![]() |
#1
|
|||
|
|||
![]()
I am trying to make a macro that will find all paragraphs containing highlighted text, and copy those paragraphs to the windows clipboard - preferably as a group, but if that's difficult, then one by one.
Below is the code from my last failed attempt, before I broke down and decided to request help Any suggestiions would be much appreciated. Marc Code:
Sub subSeveralFailedAttemps() ' ' Changes all bold formatting in the open document named Example.doc to italic formatting. ' http://www.java2s.com/Code/VBA-Excel...formatting.htm ' Dim strActiveDocFullName As String Dim strActiveDocName As String ActiveDocument.ActiveWindow.SetFocus strActiveDocFullName = ActiveDocument.FullName strActiveDocName = ActiveDocument.Name Dim objDoc As Document Set objDoc = ActiveDocument Dim objRange As Range Set objRange = objDoc.Range Dim intPosition As Long objRange.Find.Highlight = True objRange.Find.Forward = True Do While objRange.Find.Execute If objRange.HighlightColorIndex = wdYellow Then objRange.Expand Unit:=wdParagraph objRange.Copy End If intPosition = objRange.End objRange.Start = intPosition Loop ' Do While objRange.Find.Execute ' With Documents(strActiveDocName).Content.Find ' .ClearFormatting ' .Highlight = True ' With .Replacement ' .Highlight = True ' End With ' .Execute FindText:="", ReplaceWith:="", _ ' Format:=True, Replace:=wdReplaceAll ' If .Found = True Then ' .Parent.Expand Unit:=wdParagraph ' .Parent.Copy ' .Parent.Font.Bold = False ' End If ' End With ' End Sub ' subSeveralFailedAttemps() Last edited by macropod; 09-14-2012 at 08:16 PM. Reason: Added code tags & formatting |
#2
|
||||
|
||||
![]()
You can't really copy discontiguous ranges to the clipboard with a macro and, if you copy them sequentially, all you'll end up with is the last item on the clipboard.
Perhaps you could explain what you're trying to achieve.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Macro to find text in between two characters and then format selected text? | qcom | Word | 5 | 02-19-2015 11:23 PM |
![]() |
jperez84 | Word VBA | 10 | 09-19-2012 04:48 PM |
![]() |
ArthurM | PowerPoint | 4 | 02-19-2012 11:33 AM |
![]() |
g48dd | Excel | 3 | 07-16-2011 10:28 PM |
Help! Find text in doc file & copy to another file | northstarman | Word | 1 | 11-05-2010 08:15 AM |