+ Reply to Thread
Results 1 to 4 of 4

duplicate specific text and underline it

  1. #1
    Registered User
    Join Date
    01-11-2017
    Location
    London, England
    MS-Off Ver
    2003,2007,2010,2013
    Posts
    65

    Exclamation duplicate specific text and underline it

    Hello All,


    i have a huge number of files need to be translated with specific instructions


    the most complicated case which i face is to duplicate all turquoise highlighted text and make the duplicated one's first character to be underlined


    and the original one to be hidden as shown below


    Before

    1.png



    After

    2.png



    i have attached a sample file for such a case

    Thanks in advance for any hint or tips

    Cheers

    Cross Posted link: Here
    Attached Files Attached Files

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: duplicate specific text and underline it

    See replies in your cross-post.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Registered User
    Join Date
    01-11-2017
    Location
    London, England
    MS-Off Ver
    2003,2007,2010,2013
    Posts
    65

    Re: duplicate specific text and underline it

    by: gmaxey

    Sub Macro1()
    Dim oRng As Range
    Dim oRng2 As Range
    Dim i As Long

    Set oRng = ActiveDocument.Range
    With oRng.Find
    .Highlight = True
    Do While .Execute
    oRng.Font.Underline = wdUnderlineNone
    oRng.NoProofing = True
    i = Len(oRng)
    Set oRng2 = oRng.Duplicate
    oRng2.InsertAfter " " & oRng.Text
    oRng2.Characters(i + 2).Underline = wdUnderlineSingle
    oRng.Font.Hidden = True
    oRng.Start = oRng2.End
    oRng.End = ActiveDocument.Range.End
    Loop
    End With
    lbl_Exit:
    Set oRng = Nothing
    Exit Sub
    End Sub

    the code works great but it crashes at the end

    i think this is because the huge number of terms that need to be duplicated, i tried it on a file contains about 1000 terms

    or is it about the the (Loop) in the code?!

  4. #4
    Registered User
    Join Date
    01-11-2017
    Location
    London, England
    MS-Off Ver
    2003,2007,2010,2013
    Posts
    65

    Re: duplicate specific text and underline it

    Sub Macro1()
    'Graham Mayor - https://www.gmayor.com - Last updated - 31 May 2019
    Dim oRng As Range
    Dim i As Integer
    Set oRng = ActiveDocument.Range
    With oRng.Find
    .Highlight = True
    Do While .Execute
    oRng.Font.Underline = wdUnderlineNone
    oRng.NoProofing = True
    i = Len(oRng)
    oRng.InsertAfter Chr(32) & oRng.Text
    oRng.MoveEnd Count:=i + 1
    oRng.Characters(i + 2).Underline = wdUnderlineSingle
    For i = i To 1 Step -1
    oRng.Characters(i).Font.Hidden = True
    Next i
    oRng.Collapse 0
    DoEvents
    Loop
    End With
    lbl_Exit:
    Set oRng = Nothing
    Exit Sub
    End Sub


    by gmayor

    thanks a lot

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Bold and underline text
    By Simply_Me in forum Excel General
    Replies: 2
    Last Post: 03-19-2019, 08:48 PM
  2. [SOLVED] underline text within the same cell
    By aarona in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-27-2017, 08:42 PM
  3. [SOLVED] Underline text in textbox ?
    By Lukael in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-03-2014, 04:23 PM
  4. [SOLVED] Need to 'Bold' & 'Underline specific characters in a field
    By KatieKat440 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-19-2013, 03:57 PM
  5. Align msgbox text and Bold & underline certain text
    By alexnkc in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-22-2013, 11:01 PM
  6. Is there a way to underline by clicking on text?
    By atsd in forum Excel General
    Replies: 2
    Last Post: 03-19-2006, 06:12 PM
  7. [SOLVED] Borders nor underline commands remove an unusual underline. ??
    By VideoFreak in forum Excel General
    Replies: 4
    Last Post: 02-11-2006, 04:20 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1