Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-24-2009, 03:24 AM
Bahir Barak Bahir Barak is offline Select text between characters Windows XP Select text between characters Office 2003
Novice
 
Join Date: May 2009
Posts: 11
Bahir Barak is on a distinguished road
Default

OK , but when I done these changings in code and run the macro it gives this error :
((
Run-time error ,5560:
The Find What text contains a Pattern Match expression which is not valid.


))

The code after the changes become like below , and picture of the error message is in attachments .
waiting for u ......

thanks

Code:
Sub Find_and_Font()
'
' Code written by Bird_FAT
' This script uses the wildcard '*' to look for text between
' two other characters, then changes the font of 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
    Selection.Font.Color = wdColorRed
    Wend
    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
    Selection.Font.Color = wdColorRed
    Wend
End Sub
Attached Images
File Type: jpg error.JPG (12.0 KB, 47 views)
Reply With Quote
  #2  
Old 05-24-2009, 04:46 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

Quote:
Originally Posted by Bahir Barak View Post
OK , but when I done these changings in code and run the macro it gives this error :
((
Run-time error ,5560:
The Find What text contains a Pattern Match expression which is not valid.
))

AH - I see the problem - you've left wildcards as TRUE
Try this - it should work!!
Code:
Sub find_and_colour_brackets()
'
' Code written by Bird_FAT
'
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "("
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
 
    While Selection.Find.Execute
    Selection.Font.Color = wdColorRed
    Selection.Font.Italic = wdToggle
    Wend
 
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = ")"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
 
    While Selection.Find.Execute
    Selection.Font.Color = wdColorRed
    Selection.Font.Italic = wdToggle
    Wend
 
End Sub
Reply With Quote
Reply



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 05:29 AM.


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