#1
|
|||
|
|||
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 |
#2
|
|||
|
|||
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. |
#3
|
|||
|
|||
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 |
#4
|
||||
|
||||
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 |
#5
|
|||
|
|||
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 ...... |
#6
|
||||
|
||||
Quote:
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 |
#7
|
|||
|
|||
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 |
#8
|
||||
|
||||
Quote:
Code:
.Text = "(*)" Code:
.Text = "(" Code:
.Text = ")" Code:
Selection.Font.Italic = wdToggle Code:
Selection.Font.Color = wdColorRed |
#9
|
|||
|
|||
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 |
#10
|
||||
|
||||
Quote:
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 |
#11
|
|||
|
|||
it had worked .
Thanks one Globe |
|
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 |
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 |