View Full Version : Find, Copy, Paste
anthony20069
08-31-2010, 09:12 AM
hi guys,
Hope someone can help me out. Been trying to figure out how to find text, copy it and paste it into another word document with VBA.
what i am trying to do is copy all the text inside square brackets that begin with ASS and has 5 numbers after it.
any ideas?
Have attached a sample doc.
Cheers
fumei
08-31-2010, 09:56 AM
This is straightforward, although you need to actually figure out precisely what you want to do.
Demo attached.
1. file saved as .doc, not docx, as I do not use 2007, and macros are not saved if I use conversion to 2007 format. So, I added a commandbutton to click.
2. as you did not specifiy not to do so, the text put into the new document includes the brackets.
3. as you did not specify, the text put into the new document is completely sequential - no paragraph marks between each found "[assxxxxxxx]"
Both #2 and #3 are very easily changed.
anthony20069
09-01-2010, 01:25 AM
Gerry, that is perfect. Thanks for this. On #3, could we make it to put them each on a new line?
hitech
09-01-2010, 03:56 AM
You can find from (thezcorp) an article containing the sample codes.
fumei
09-01-2010, 10:12 AM
"Thanks for this. On #3, could we make it to put them each on a new line?"
Add a vbCrLf (a paragraph mark) with each insertion of the found text.
TheOtherDoc.Range.InsertAfter r.Text & vbCrLf
"JoJo Zawawi's World-Famous Word-VBA Code Samples"
World-Famous?
Really?
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.