Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 05-02-2009, 02:36 AM
Bird_FAT's Avatar
Bird_FAT Bird_FAT is offline Select text between characters Select text between characters 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
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
The characters of my received emails are little squares! HELP! chocolatecookies Outlook 0 12-17-2008 04:17 PM
Templates: automatic text generation from Rich Text content control Chickenmunga Word 0 10-01-2008 11:16 AM
special/escape/insertion characters in word manojbmsce Word 0 09-25-2008 06:40 AM
Select text between characters Making sure the correct number of characters are entered. leroytrolley Excel 1 07-25-2008 06:38 AM
escape characters LadyReader Word VBA 0 09-06-2006 12:09 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:32 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft