#1
|
|||
|
|||
prefix all underlined text with a tab
Hi, I am new to word VBA and would appreciate some help. I need a macro that can search/iterate through the active document and find all the instances of underlined text. Each time it finds underlined text, the code needs to insert a tab immediately before the underlined text. Can anyone help? thanks, Mark |
#2
|
|||
|
|||
Code:
Sub ScratchMacro() 'A basic Word macro coded by Greg Maxey Dim oRng As Range Set oRng = ActiveDocument.Range With oRng.Find .Font.Underline = wdUnderlineSingle While .Execute oRng.InsertBefore vbTab oRng.Collapse wdCollapseEnd Wend End With lbl_Exit: Exit Sub End Sub |
#3
|
|||
|
|||
or, if there is already a tab immediately preceding the underlined text and you want to avoid duplicates use:
Code:
Sub ScratchMacro() 'A basic Word macro coded by Greg Maxey Dim oRng As Range Set oRng = ActiveDocument.Range With oRng.Find .Font.Underline = wdUnderlineSingle While .Execute If Not Asc(oRng.Characters.First.Previous) = 9 Then oRng.InsertBefore vbTab oRng.Collapse wdCollapseEnd End If Wend End With lbl_Exit: Exit Sub End Sub |
#4
|
|||
|
|||
Perfect. Thank you
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Find entries lacking prefix and then add prefix. | gsteel | Excel | 2 | 08-28-2017 11:36 AM |
Word - text in red and underlined | ghphoto | Word | 3 | 02-18-2013 08:39 AM |
Create an underlined form field within an already underlined line? | lwisniewski | Word | 1 | 01-21-2013 05:49 AM |
Underlined copied text box | LarryStroup | PowerPoint | 0 | 09-30-2011 11:22 AM |
PP Slide copied text is underlined | LarryStroup | PowerPoint | 0 | 05-20-2011 11:16 AM |