|
-
Jan 22nd, 2007, 04:11 PM
#1
Thread Starter
New Member
Macro to find all text in word
HI
I need to run a macro which will find appriopriate entries of text in a document,as given below. I've got it working fine with wildcards. The only problems is the "Find All" option. I want to select all instances of this text in the document - this can be done straight from the Edit/find menu - but I cannot find any way to do this in the macro. I need to do this so that I can then copy the data into Exel.
Private Sub CmdOK_Click()
UserForm1.Hide
Selection.Find.ClearFormatting
With Selection.Find
.Text = "??/01/2007 ???????? terryja1"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
.Execute
End With
Selection.Copy
Selection.Copy
finalspread.Sheets("Bhad").Select
finalspread.ActiveSheet.Paste
HELP!
-
Jan 22nd, 2007, 05:02 PM
#2
Re: Macro to find all text in word
Hi
Welcome to the forums
Is this what you are trying to do?
VB Code:
Selection.Find.ClearFormatting
With Selection.Find
.Text = "example" 'your text here
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
once you get this you can paste the data to a worksheet(if you want the code for that, lemme know)...
Hope this helps...
Last edited by Siddharth Rout; Jan 22nd, 2007 at 05:05 PM.
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Jan 23rd, 2007, 04:09 AM
#3
Thread Starter
New Member
Re: Macro to find all text in word
Cheers, but I've run that and it's doing the same as the code I've already got. Hmm, having read my first post I don't think I've explained this very well. At the moment, it only finds and highlights the first instance of the text in the document. I want to get it to highlight every instance. Like I say, you can do this from Edit/Find on the toolbar by ticking the "Highlight all items found in" tickbox. I've tried recording this so that I can see how its doing this, but even that doesn't work if you rerun it.
-
Jan 23rd, 2007, 05:12 AM
#4
Re: Macro to find all text in word
Hmm, I see what you mean...
and guess what it is not letting me run other macros as well... for example if i want to 'Unbold' all 'bold' characters in the Word Doc, it's not letting me...
let me see if i can figure out what the problem is...
VB Code:
With Selection.Find
.ClearFormatting
.Font.Bold = True
With .Replacement
.ClearFormatting
.Highlight = True
End With
.Execute Forward:=True, FindText:="", ReplaceWith:="", _
Format:=True
End With
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|