Microsoft Word Macro help

Associate
Joined
26 Oct 2008
Posts
168
Hey all, not sure if this is the right forum but I have quite a big issue I need helping with.

I've been asked to work out how to make a macro for microsoft word to help a friends Father so he doesn't have to CTRL + F to search for the reference numbers each time.

The macro as I understand it for the example he'd like to see before it becomes complicated even more need to be able to do the following functions.

Start with a reference number example: 105.1.1 with several in between and say the final reference number was 214.5.1. He'd like it so that pressing a keyboard key such as enter would check/skip to the next reference code in the report file. So say I have all reference codes added to the macro, if its not used within the report he has it'll skip that and find the next working reference number inside the report.

Thanks in advance for any help or links to let me get my head around this.
 
Here you go

Code:
Sub search()
'
' search Macro
' Macro recorded 2/25/2010
'
Dim arr(2) As String
arr(0) = "105.1.3"
arr(1) = "190.1.1"

Dim s As Variant

    For Each s In arr()
        Selection.Find.ClearFormatting
        With Selection.Find
            .Text = s
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        
        If Selection.Find.Found Then
                If MsgBox("Move Next?", vbInformation Or vbYesNo) = vbNo Then Exit For
        End If
    Next
End Sub
 
Last edited:
Nah I just wrote it from scratch sorry.

To get an idea though. Click record macro and then ctrl+f, enter some text and click find and then stop the macro recorder.

You can then edit the macro and it will look like that above. The msgbox bit was added so that it stops after each find rather than just going to the last one.
 
Back
Top Bottom