Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-24-2015, 12:02 PM
spc94 spc94 is offline Finding and Replacing a word with text copied to clip board Windows 7 64bit Finding and Replacing a word with text copied to clip board Office 2010 64bit
Novice
Finding and Replacing a word with text copied to clip board
 
Join Date: Jun 2015
Location: Ohio, USA
Posts: 8
spc94 is on a distinguished road
Default Finding and Replacing a word with text copied to clip board

I am trying to find a specific word and replace with text copied to my clip board. Currently I am searching the word replacing it with nothing and then pasting it there but it does seem to work correctly any suggestions.

ChangeFileOpenDirectory "X:\sconner\CCD Damage Mechanisms\Mechanisms\"
Documents.Open FileName:= _
"X:\sconner\CCD Damage Mechanisms\Mechanisms\Underdeposit Corrosion.docx", _
ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
wdOpenFormatAuto, XMLTransform:=""
Selection.WholeStory
Selection.Copy
ActiveWindow.Close
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "(NEXT MECH)"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With


Selection.Find.Execute Replace:=wdReplaceAll
Selection.PasteAndFormat (wdUseDestinationStylesRecovery)
Reply With Quote
  #2  
Old 06-24-2015, 03:00 PM
macropod's Avatar
macropod macropod is offline Finding and Replacing a word with text copied to clip board Windows 7 64bit Finding and Replacing a word with text copied to clip board 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 use Find/Replace on clipboard contents - only in a document.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-24-2015, 10:05 PM
gmayor's Avatar
gmayor gmayor is offline Finding and Replacing a word with text copied to clip board Windows 7 64bit Finding and Replacing a word with text copied to clip board Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

While Paul is correct, if you are copying the content of the named document into the active document then the following will do that. You don't have to use the clipboard (though you could).

Code:
Dim oDoc As Document
Dim oSource As Document
Dim oRng As Range
    Set oDoc = ActiveDocument
    Set oSource = Documents.Open(Filename:= _
                                 "X:\sconner\CCD Damage Mechanisms\Mechanisms\Underdeposit Corrosion.docx", _
                                 ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
                                 PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
                                 WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
                                 wdOpenFormatAuto, XMLTransform:="")
    Set oRng = oDoc.Range
    With oRng.Find
        Do While .Execute(FindText:="(NEXT MECH)")
            oRng.FormattedText = oSource.Range.FormattedText
            oRng.Collapse 0
        Loop
    End With
    oSource.Close 0
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #4  
Old 06-25-2015, 04:46 AM
spc94 spc94 is offline Finding and Replacing a word with text copied to clip board Windows 7 64bit Finding and Replacing a word with text copied to clip board Office 2010 64bit
Novice
Finding and Replacing a word with text copied to clip board
 
Join Date: Jun 2015
Location: Ohio, USA
Posts: 8
spc94 is on a distinguished road
Default Multiple Check boxes

Graham thank you for the help that worked! Now in my user form I have multiple check boxes that all have the same code as the first just different sources. How is it that I get them to post one after another when I execute the userform. I initially entered NEXT MECH as the end of each sources paragraph but it does seem to find it. Any Suggestions?
Reply With Quote
Reply

Tags
find and replace, userforms, word vba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding varying text in an MS Word file sergiodcq Word 1 07-08-2014 03:12 AM
Copied shape/text box pastes as an image in Word spectator Word 0 06-04-2014 08:45 AM
Finding and Replacing a word with text copied to clip board Finding and replacing fonts and styles Adriano Word VBA 10 03-17-2013 07:08 PM
Underlined copied text box LarryStroup PowerPoint 0 09-30-2011 11:22 AM
PP Slide copied text is underlined LarryStroup PowerPoint 0 05-20-2011 11:16 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:32 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