Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.

Windows 7: writing macros for word 2007

23 Oct 2013   #1

Windows 7 Ultimate 64-bit and 32-bit
writing macros for word 2007


I can record simple search and replace macros in word 2007 but my abilities stop there.

Back in the days when I was using Word Perfect I could easily write macros that search for a string, exit the search function, select all text until a different string occurred, and then marked that text red, and then repeat until end of document.
In that way I could easily, e.g. in text formatted as below, find and colour everything Bob says red. I would search for "Bob:" turn selection on, move and select everything until the next ^p (which signals that Bob has stopped speaking), change formatting to red, and then repeat until end of document.

Ted: Hi, Bob. How are you?
Bob: Fine. And you?
Ted: I've got a splitting head ache.
Bob: You-d better have an aspirin, then.
// ...etc etc etc... //

In MS-Word 2007 I have not been able to perform such automation, and I have no luck googling for tutorials either. I would appreciate if someone could point me in the right direction.


My System SpecsSystem Spec

09 Nov 2013   #2

Windows 7

Hope this help...

Sub FindBob()
    ' create a loop that continues until the end of the doc
    Do Until ActiveDocument.Bookmarks("\Sel").Range.End = _
        ' find Bob:
        With Selection.Find
            .Text = "Bob:"
        End With
        ' Once Bob: is found then select to the paragraph mark
        Selection.GoTo what:=wdGoToBookmark, Name:="\para"
        ' format the selected para
        Selection.Font.ColorIndex = wdRed
        ' move insertion point to the end of the para so the find can continue
        Char = Selection.EndOf(Unit:=wdParagraph, Extend:=wdMove)
End Sub
My System SpecsSystem Spec

 writing macros for word 2007

Thread Tools

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 03:49 AM.
Twitter Facebook Google+

Windows 7 Forums

Seven Forums Android App Seven Forums IOS App

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33