#1
|
|||
|
|||
Underline particular parts of words in macro
Hi guys. VBA newbie here. I use word macros to translate text from Russian to English. I am trying to underline 'TS' of TSIATIM but the macro underlines only the first word.
I don't have the code with me now but I recorded it as below... Ctrl + home Find TSIATIM Press left arrow key one time Press shift + right arrow key two times Press ctrl + u Press ctrl + right arrow key I put this code in a loop but sometimes underlines from TS are removed... I think the loop should stop at the last occurrence of TSIATIM. But I don't know how to write this code. I don't have any programming background. I would greatly appreciate any help. Thank you! |
#2
|
||||
|
||||
The following will work
Code:
Sub UnderlineTS() Dim oRng As Range Set oRng = ActiveDocument.Range With oRng.Find Do While .Execute(FindText:="TSIATIM") oRng.End = oRng.Start + 2 oRng.Underline = wdUnderlineSingle oRng.Collapse 0 Loop End With lbl_Exit: Set oRng = Nothing Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Thanks a lot @gmayor
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Macro to find and replace headings in bold and underline | redzan | Word VBA | 4 | 02-13-2016 12:24 PM |
Translating words that parts of a menu | LoekyH1955 | Word | 1 | 01-29-2016 10:56 PM |
Macro for changing formatting of certain parts of a word | McBanjo | Word VBA | 10 | 12-18-2014 09:23 PM |
Macro to highlight words | bertietheblue | Word VBA | 9 | 07-01-2013 12:39 PM |
Macro for select words? | Megan Sprack | Word | 1 | 08-23-2012 03:03 PM |