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
gridsystems

Windows 7 Pro 64-bit
 
 
writing macros for word 2007

Hi,

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.

Thanks!


My System SpecsSystem Spec
.
09 Nov 2013   #2
OfficeNewb

Windows 7
 
 

Hope this help...

Code:
Sub FindBob()
'
    ' create a loop that continues until the end of the doc
    Do Until ActiveDocument.Bookmarks("\Sel").Range.End = _
                ActiveDocument.Bookmarks("\EndOfDoc").Range.End
    
        ' find Bob:
        Selection.Find.ClearFormatting
        With Selection.Find
            .Text = "Bob:"
        End With
        Selection.Find.Execute
        
        ' 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)
    Loop
End Sub
My System SpecsSystem Spec
Reply

 writing macros for word 2007




Thread Tools




Similar help and support threads
Thread Forum
Macros in Word Documents
Hello Good People of the Forum: Whenever I attempted to open a Word file I get the attached message. I have no idea what a macro is. Thanks in advance for any help. Regards Powell Lucas
Microsoft Office
need word 2007 AND word 2010, how to set file associations
Because I do teaching for people who have both versions (2007 & 2010) of Word, I have to keep both on my computer. How do I get .doc and .docx to associate with Word 2010? Because I work mostly in 2010, I want to default to opening with 2010 but I can't do it. When I do try to correct the...
Microsoft Office
Word 2007 Can't open encrypted docx from Word 2010
When I send some friends a password protected word document created in Word 2010 they can't open it using word 2007 which is compatible with docx by using the correct password. I have no choice but to send as a Word doc instead of docx so they can open it. Word 2007 User 1: Word launches no...
Microsoft Office
Cannot access the Ribbon functions in Excel 2007 or Word 2007
I have Office 2007 on Windows 7. When I am working on a sheet (or document) the ribbon can become inaccessible, nothing works when I click it (like a 'Not Responding' screen). If, I switch to another open sheet/doc and then switch back the ribbon is accessible again! I have...
Microsoft Office
Articles writing software or how to view keyword desity on MS Word.
I just start blogging in blogger. I'm not a native English speaker, so i have lots of spelling and grammar mistakes when i writing English articles. So i want create SEO (search engine friendly) friendly articles, so are there any software contain following features. *Check Grammar, spelling and...
Software
Macros won't save Word 2003
Using Win 7 Home premium and Word 2003. Record new macros, but they're not available if I close and re-open Word. Have renamed normal.dot to oldnormal.dot but don't see a new normal template. Have Acrobat 9.0 but found past problems only with Acrobat 7. Everything worked fine using Word 2003 with...
Microsoft Office


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 00:58.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App