Microsoft Office Forums Changing words with bold and italics and turning "regular" words into italicized and bold ones

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-25-2019, 07:45 AM
thiagoafdoria thiagoafdoria is offline Changing words with bold and italics and turning "regular" words into italicized and bold ones Windows 10 Changing words with bold and italics and turning "regular" words into italicized and bold ones Office 2019
Novice
Changing words with bold and italics and turning "regular" words into italicized and bold ones
 
Join Date: Feb 2017
Posts: 13
thiagoafdoria is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 11-25-2019, 08:16 PM
macropod's Avatar
macropod macropod is online now Changing words with bold and italics and turning "regular" words into italicized and bold ones Windows 7 64bit Changing words with bold and italics and turning "regular" words into italicized and bold ones Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,673
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

For some code to get you started, see my posts in: https://www.msofficeforums.com/word-...nderlined.html
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 11-29-2019, 10:30 AM
thiagoafdoria thiagoafdoria is offline Changing words with bold and italics and turning "regular" words into italicized and bold ones Windows 10 Changing words with bold and italics and turning "regular" words into italicized and bold ones Office 2019
Novice
Changing words with bold and italics and turning "regular" words into italicized and bold ones
 
Join Date: Feb 2017
Posts: 13
thiagoafdoria is on a distinguished road
Default

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
To do the opposite, I've tried the following:

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
It does work for italics, but not for bold. Any ideas of how to make it work for bold too?

Thank's!
Reply With Quote
  #4  
Old 11-29-2019, 01:30 PM
macropod's Avatar
macropod macropod is online now Changing words with bold and italics and turning "regular" words into italicized and bold ones Windows 7 64bit Changing words with bold and italics and turning "regular" words into italicized and bold ones Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,673
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

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
[MS MVP - Word]
Reply With Quote
  #5  
Old 12-02-2019, 11:41 AM
thiagoafdoria thiagoafdoria is offline Changing words with bold and italics and turning "regular" words into italicized and bold ones Windows 10 Changing words with bold and italics and turning "regular" words into italicized and bold ones Office 2019
Novice
Changing words with bold and italics and turning "regular" words into italicized and bold ones
 
Join Date: Feb 2017
Posts: 13
thiagoafdoria is on a distinguished road
Default

Thank you very much, macropod!

I've tried

Code:
.Text = \*\*([!\*]@)\*\*
but an error appeared; then I've put the quotation marks between \*\*([!\*]@)\*\* and now works pefectly. Thank's again, 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
Reply With Quote
Reply

Tags
bold, italics, macro

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing words with bold and italics and turning "regular" words into italicized and bold ones All words in document appear bold but are not! Ezra Word 4 07-31-2017 06:53 AM
Changing words with bold and italics and turning "regular" words into italicized and bold ones 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
Changing words with bold and italics and turning "regular" words into italicized and bold ones Is there a way to use "find/replace" to find italics words? slayda Word 3 09-14-2011 02:16 PM
Changing words with bold and italics and turning "regular" words into italicized and bold ones Making Multiple Words Bold mtk989 Word 2 06-25-2011 11:27 AM


All times are GMT -7. The time now is 02:02 AM.


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