Consulting

Results 1 to 4 of 4

Thread: Find string within word document

  1. #1
    VBAX Regular
    Joined
    Mar 2022
    Posts
    8
    Location

    Find string within word document

    I have categories like:
    a, Content.
    a. Content:
    a, Content:
    I tried the following code with no success

    Sub A123()
     
        On Error Resume Next
        
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find.Replacement.Font
            .Bold = True
            .Color = wdColorBlue
        End With
        With Selection.Find
            .text = "(a[,\.] Noi dung)([.:])"
            .Replacement.text = "a) Noi dung"
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = True
    End With
        Selection.Find.Execute Replace:=wdReplaceAll
    End Sub

    Sorry my English is very bad. Thank you
    Last edited by Paul_Hossler; 05-10-2022 at 09:31 AM.

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,340
    Location
    1. I added CODE tags to your macro to format it

    2. Not exactly sure what you're looking to do, but based on looking at the macro, this seems to find 'Noi dung' and makes it blue


    Option Explicit
    
    
    Sub A123()
        
        With Selection.Find
            .ClearFormatting
            .Replacement.ClearFormatting
            
            With .Replacement.Font
                .Bold = True
                .Color = wdColorBlue
            End With
        
        
            .Text = "(a[,\.] Noi dung)([.:])"
            .Replacement.Text = "a) Noi dung\2"
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = True
            .Execute Replace:=wdReplaceAll
        
        End With
    End Sub
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Regular
    Joined
    Mar 2022
    Posts
    8
    Location
    Ok. Thank you very much
    Last edited by macropod; 05-12-2022 at 09:11 PM. Reason: Deleted unnecessary quote of post replied to.

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,340
    Location
    Quote Originally Posted by lamnbj View Post
    Ok. Thank you ...
    BTW, it's not necessary to include the entire post in a [Reply With Quote]

    You can edit the material to just what you need to reference, so you didn't need the macro

    It just makes a post easier to read is all
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •