Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-14-2012, 03:06 PM
marceepoo marceepoo is offline Find & selected paras with highlighted text & copy to clipboard Windows 7 64bit Find & selected paras with highlighted text & copy to clipboard Office 2010 64bit
Novice
Find & selected paras with highlighted text & copy to clipboard
 
Join Date: Sep 2012
Posts: 22
marceepoo is on a distinguished road
Default Find & selected paras with highlighted text & copy to clipboard

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
Reply With Quote
  #2  
Old 09-14-2012, 08:20 PM
macropod's Avatar
macropod macropod is offline Find & selected paras with highlighted text & copy to clipboard Windows 7 64bit Find & selected paras with highlighted text & copy to clipboard Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
Reply



Similar Threads
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
Find & selected paras with highlighted text & copy to clipboard Macro that can find phrase and then find another and copy jperez84 Word VBA 10 09-19-2012 04:48 PM
Find & selected paras with highlighted text & copy to clipboard Mark text in a text box and copy to clipboard (with button) ArthurM PowerPoint 4 02-19-2012 11:33 AM
Find & selected paras with highlighted text & copy to clipboard copy without using clipboard? 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

Other Forums: Access Forums

All times are GMT -7. The time now is 04:48 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft