Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-27-2019, 07:09 AM
mwperkins mwperkins is offline prefix all underlined text with a tab Windows 10 prefix all underlined text with a tab Office 2016
Novice
prefix all underlined text with a tab
 
Join Date: Jun 2019
Posts: 2
mwperkins is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 06-27-2019, 07:11 AM
gmaxey gmaxey is online now prefix all underlined text with a tab Windows 10 prefix all underlined text with a tab Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 06-27-2019, 07:15 AM
gmaxey gmaxey is online now prefix all underlined text with a tab Windows 10 prefix all underlined text with a tab Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #4  
Old 06-30-2019, 04:04 AM
mwperkins mwperkins is offline prefix all underlined text with a tab Windows 10 prefix all underlined text with a tab Office 2016
Novice
prefix all underlined text with a tab
 
Join Date: Jun 2019
Posts: 2
mwperkins is on a distinguished road
Default

Perfect. Thank you
Reply With Quote
Reply



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
prefix all underlined text with a tab Word - text in red and underlined ghphoto Word 3 02-18-2013 08:39 AM
prefix all underlined text with a tab 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

Other Forums: Access Forums

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


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