View Single Post
 
Old 05-02-2009, 02:36 AM
Bird_FAT's Avatar
Bird_FAT Bird_FAT is offline Office 2007
Expert
 
Join Date: Apr 2009
Location: South East
Posts: 271
Bird_FAT is on a distinguished road
Default VBA - wildcards loop

He davers,

Sorry for not posting before - been a bit busy.

In Word, the Find function can be set to use 'wildcards' - this should help you with your task. Below is some script that you can paste into your VBA window (Alt+F11) and then run from your macro menu.

Code:
Sub Find_and_Italicise()
'
' Macro recorded by Bird_FAT
' This macro uses the wildcard '*' to look for text
' between to underscores, then italicises the text.
' The While/Wend statement at the end causes it to
' loop until it reaches the end of the document.
'
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "_*_"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
    End With
    While Selection.Find.Execute
    Selection.Font.Italic = wdToggle
    Wend
End Sub
To use the wildcard feature, when you use Find/Find and Replace, select 'More' (if not already visible) and tick the 'Use wildcards' box - if you open Help and type 'wildcards' and choose the second option in the list it has some really great information there as a reference.
Reply With Quote