Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-24-2018, 06:03 AM
Ktulu Ktulu is offline Underline particular parts of words in macro Windows 7 32bit Underline particular parts of words in macro Office 2007
Novice
Underline particular parts of words in macro
 
Join Date: Apr 2018
Posts: 6
Ktulu is on a distinguished road
Default 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!
Reply With Quote
  #2  
Old 04-24-2018, 06:44 AM
gmayor's Avatar
gmayor gmayor is offline Underline particular parts of words in macro Windows 10 Underline particular parts of words in macro Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #3  
Old 04-24-2018, 07:49 PM
Ktulu Ktulu is offline Underline particular parts of words in macro Windows 7 32bit Underline particular parts of words in macro Office 2007
Novice
Underline particular parts of words in macro
 
Join Date: Apr 2018
Posts: 6
Ktulu is on a distinguished road
Default

Thanks a lot @gmayor
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Underline particular parts of words in macro 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
Underline particular parts of words in macro Macro for changing formatting of certain parts of a word McBanjo Word VBA 10 12-18-2014 09:23 PM
Underline particular parts of words in macro Macro to highlight words bertietheblue Word VBA 9 07-01-2013 12:39 PM
Underline particular parts of words in macro Macro for select words? Megan Sprack Word 1 08-23-2012 03:03 PM

Other Forums: Access Forums

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


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