Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-19-2020, 02:20 PM
Genericname1111 Genericname1111 is offline Macro to highlight only start of line, not past tab spaces (Word 97) Windows 7 64bit Macro to highlight only start of line, not past tab spaces (Word 97) Office 97-2003
Novice
Macro to highlight only start of line, not past tab spaces (Word 97)
 
Join Date: Aug 2019
Posts: 17
Genericname1111 is on a distinguished road
Default Macro to highlight only start of line, not past tab spaces (Word 97)

Hi, I've got a macro to highlight the start of each line in my document.

A(tab space here)(tab space here) Text

The problem is when there's no text after the tab spaces (when I haven't typed anything else on that line yet), it highlights the whole line, which means when I go on to that line to type, the text I type is highlighted. Is there a way I could get it to not highlight past the tab spaces? Here is my current macro:

Sub ReplaceAwithhighlightedtext()
With Selection.Find
.Text = "A^t"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False


.Forward = False
Do While .Execute
Selection.Range.HighlightColorIndex = wdRed
Loop
End With
Application.Run MacroName:="Normal.NewMacros.ClearFindAndReplacePa rameters"
End Sub

It extends past the tab spaces, which I'm not sure how to fix.
Reply With Quote
  #2  
Old 01-22-2020, 11:25 AM
gmaxey gmaxey is offline Macro to highlight only start of line, not past tab spaces (Word 97) Windows 10 Macro to highlight only start of line, not past tab spaces (Word 97) Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,427
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 ReplaceAwithhighlightedtext()
Dim oRng As Range
  Set oRng = ActiveDocument.Range
  With oRng.Find
    .Text = "A^t"
    Do While .Execute
      oRng.HighlightColorIndex = wdRed
      oRng.Collapse wdCollapseEnd
      oRng.HighlightColorIndex = wdAuto
    Loop
  End With
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to highlight only start of line, not past tab spaces (Word 97) start a macro with command Line startup switches Fesazu Word 3 02-08-2018 12:15 AM
Macro to highlight only start of line, not past tab spaces (Word 97) issue with highlight macro word 2010 jamesnavoy Word VBA 2 01-29-2017 08:32 AM
Macro to highlight only start of line, not past tab spaces (Word 97) macro to add brackets to each line and add single quotes to each word in the line bracketandquotes Word VBA 17 02-16-2015 03:51 PM
Macro to highlight only start of line, not past tab spaces (Word 97) Macro Question: Need help making a macro to highlight the first word in every sentence LadyAna Word 1 12-06-2014 10:39 PM
Macro to highlight only start of line, not past tab spaces (Word 97) Macro to highlight text between 2 points in word 2010 jsilva1950 Word VBA 2 04-25-2013 12:21 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:31 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