Microsoft Office Forums Select text between characters

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-19-2008, 07:57 AM
davers davers is offline Select text between characters Windows XP Select text between characters Office XP
Novice
Select text between characters
 
Join Date: Dec 2008
Posts: 3
davers is on a distinguished road
Default Select text between characters

Hi everyone! I'm editing large documents and one of the things I need to do is change the font type of all words in a sentence that fall between 2 characters. For instance in this example:

"This is my example text, _can you believe this!_ How can this be?"

Needs to be changed to "This is my example text, can you believe this! How can this be?"

So, everything that falls between the "underscores" needs to be italicized... Does anyone know how to use VBA to automate this?

Thanks for any help!!

Dave
Reply With Quote
  #2  
Old 12-19-2008, 08:59 AM
dylane dylane is offline Select text between characters Windows 7 Select text between characters Office 2007
Novice
 
Join Date: Dec 2008
Posts: 7
dylane is on a distinguished road
Default

Not sure how to do what you ask with VBA in Word, although there is probably a way. But you might be better served using a type setting program like LaTeX. I myself don't have any experience with this program, but I think it will do basically what you want (although you might need to replace the "_" with a different symbol).

If the document isn't really long, it might be better to just do a Find for all underscores and do direct formatting to the text you want italicized. Not as elegant, but many times a quicker approach.
Reply With Quote
  #3  
Old 05-01-2009, 10:35 AM
davers davers is offline Select text between characters Windows XP Select text between characters Office XP
Novice
Select text between characters
 
Join Date: Dec 2008
Posts: 3
davers is on a distinguished road
Default

Hmm...I'll take a look at LaTex. Thanks for the link dylane. I'll have to work on the code for a bit.

Thanks,

Dave
Reply With Quote
  #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
  #5  
Old 05-08-2009, 08:58 PM
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

Hi my dear Bird Fat thanks alot for this useful instructions,

but i need to select text automatically between two quotes in MS WORD 2003 , and want to change its font type just to bold , if you had write for me VBA code for this command , I will be very thinkful for you ,

I am waiting for u ......
Reply With Quote
  #6  
Old 05-09-2009, 12:35 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
Hi my dear Bird Fat thanks alot for this useful instructions,

but i need to select text automatically between two quotes in MS WORD 2003 , and want to change its font type just to bold , if you had write for me VBA code for this command , I will be very thinkful for you ,

I am waiting for u ......
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 = "_*_"       '<------ Change the search choice
        .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  '<------ Change the Font choice
    Wend
End Sub
Just use the code from before and change the 'find' choice (put the characters you are looking for on either side of the *) and the word 'italic' for 'bold' in the line before 'Wend' - See the red markers above.
Reply With Quote
  #7  
Old 05-20-2009, 05:31 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

My dear :

I try the macro with changing the code , but it did not works with me , there is the file with attachments it is just empty foonotes , I want to change just the font or colour of the quotes not the number of footnoe,

Thankssss
Attached Files
File Type: doc Footnotes.doc (36.0 KB, 5 views)
Reply With Quote
  #8  
Old 05-20-2009, 11:19 PM
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
My dear :

I try the macro with changing the code , but it did not works with me , there is the file with attachments it is just empty foonotes , I want to change just the font or colour of the quotes not the number of footnoe,

Thankssss
Umm...You have:
Code:
.Text = "(*)"
as your search choice. This is telling the search and replace to change the brackets AND EVERYTHING IN BETWEEN! If you ONLY want it to effect the brackets, then you need to enter the brackets ONLY. You will need to repeat the code to search 1st for
Code:
.Text = "("
, followed by copying the code again (Everything from 'Selection.Find.ClearFormatting' to 'Wend'), and changing it to
Code:
.Text = ")"
Also you have it changing to Italic, not colour?
Code:
Selection.Font.Italic = wdToggle
you will need to change it to a colour code instead
Code:
Selection.Font.Color = wdColorRed
Reply With Quote
  #9  
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, 18 views)
Reply With Quote
  #10  
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
  #11  
Old 05-24-2009, 05:15 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

it had worked .

Thanks one Globe
Reply With Quote
Reply

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


All times are GMT -7. The time now is 03:18 PM.


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