Results 1 to 4 of 4

Thread: Macro to find all text in word

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2007
    Posts
    2

    Talking 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!

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Macro to find all text in word

    Hi

    Welcome to the forums

    Is this what you are trying to do?

    VB Code:
    1. Selection.Find.ClearFormatting
    2.  
    3.     With Selection.Find
    4.         .Text = "example"  'your text here
    5.         .Replacement.Text = ""
    6.         .Forward = True
    7.         .Wrap = wdFindContinue
    8.         .Format = False
    9.         .MatchCase = False
    10.         .MatchWholeWord = False
    11.         .MatchWildcards = False
    12.         .MatchSoundsLike = False
    13.         .MatchAllWordForms = False
    14.     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

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2007
    Posts
    2

    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.

  4. #4
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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:
    1. With Selection.Find
    2.     .ClearFormatting
    3.     .Font.Bold = True
    4.     With .Replacement
    5.         .ClearFormatting
    6.         .Highlight = True
    7.     End With
    8.     .Execute Forward:=True, FindText:="", ReplaceWith:="", _
    9.         Format:=True
    10. 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
  •  



Click Here to Expand Forum to Full Width