|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Changing words with bold and italics and turning "regular" words into italicized and bold ones
Hi there!
First of all, I apologize for tried to discuss this earlier in an old thread whose theme is completely different from the one I'm bringing here. After that, I've searched for some threads that could contain answers for my questions, but I didn't succeed. Then I started this new thread. I was wondering if a macro could make each bold word be between two asterisks (word -> **word**) and each italicized word to be between two underlines (italics -> __italics__). Is that possible? And another macro could do the reverse of that (**word** -> word; __italics__ -> italics)? I'm very new to VBA and I don't know if this is a job for a macro. Perharps what I've described may be achieved by other means? Thank's for any help! Thiago Last edited by thiagoafdoria; 11-25-2019 at 08:15 PM. |
#2
|
||||
|
||||
For some code to get you started, see my posts in: https://www.msofficeforums.com/word-...nderlined.html
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Hi,
macropod, I'm sorry. I understood that you had suggested that I continue the discussion on that other thread; my mistake. I found some codes there but initially I couldn't understand them. However, after some trial and error I took advantage of one of the codes you posted and now I can transform make each bold word be between two asterisks (word -> **word**) and each italicized word to be between two underlines (italics -> __italics__). In case of anyone interested, that's the macro I'm using: Code:
Sub Demo1 ( ) Application.ScreenUpdating = False With ActiveDocument.Range.Find .ClearFormatting .Replacement.ClearFormatting .Format = True .Forward = True .MatchWildcards = True .Wrap = wdFindContinue .Font.Bold = True .Replacement.Text = "**^&**" .Execute Replace:=wdReplaceAll .ClearFormatting .Font.Italic = True .Replacement.Text = "__^&__" .Execute Replace:=wdReplaceAll End With Application.ScreenUpdating = True End Sub Code:
Sub Demo 2 ( ) Application.ScreenUpdating = False With ActiveDocument.Range.Find .ClearFormatting .Replacement.ClearFormatting .Format = True .Forward = True .MatchWildcards = True .Wrap = wdFindContinue .Replacement.Text = "\1" .Text = "\**(*)\**" .Replacement.Font.Bold = True .Execute Replace:=wdReplaceAll .Replacement.ClearFormatting .Text = "\__(*)\__" .Replacement.Font.Italic = True .Execute Replace:=wdReplaceAll End With Application.ScreenUpdating = True End Sub Thank's! |
#4
|
||||
|
||||
Asterisks in a wildcard Find are themselves wildcards, so you can't use them both as literals and as wildcards the way you've done. Try:
.Text = "\*\*([!\*]@)\*\*"
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Thank you very much, macropod!
For those whose are interested, the final result is this: Code:
Sub Demo 2 ( ) Application.ScreenUpdating = False With ActiveDocument.Range.Find .ClearFormatting .Replacement.ClearFormatting .Format = True .Forward = True .MatchWildcards = True .Wrap = wdFindContinue .Replacement.Text = "\1" .Text = "\*\*([!\*]@)\*\*" .Replacement.Font.Bold = True .Execute Replace:=wdReplaceAll .Replacement.ClearFormatting .Text = "\__(*)\__" .Replacement.Font.Italic = True .Execute Replace:=wdReplaceAll End With Application.ScreenUpdating = True End Sub |
Tags |
bold, italics, macro |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
All words in document appear bold but are not! | Ezra | Word | 4 | 07-31-2017 06:53 AM |
Bold & Italics NOT turning off with keyboard shortcuts | Tweaker | Word | 6 | 08-26-2015 03:07 PM |
remove repeated words with " macro " or " wild cards " in texts with parentheses and commas | jocke321 | Word VBA | 2 | 12-10-2014 11:27 AM |
Is there a way to use "find/replace" to find italics words? | slayda | Word | 3 | 09-14-2011 02:16 PM |
Making Multiple Words Bold | mtk989 | Word | 2 | 06-25-2011 11:27 AM |