Question
astronawta on Sat, 06 May 2017 23:28:52
I need to create a Macro for Word 2013 to find the next consecutive dot and space ". " in text, select the following 750 characters without spaces and highlight this selected text in yellow. Can anybody help me?
Replies
WayneAKing on Sun, 07 May 2017 00:33:31
I need to create a Macro for Word 2013 to find the next consecutive dot and space ". " in text, select the following 750 characters without spaces and highlight this selected text in yellow.
Why did you choose this forum? It's for issues related to the Visual Basic
programming language. A better forum might be:
Microsoft Office for Developers > Word for Developers
https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=worddev
- Wayne
macropod on Mon, 08 May 2017 04:20:47
Try:
Sub Demo()
With Selection
.MoveStartUntil ".", wdForward
Do While .Characters.First.Next <> " "
If .Characters.First.Next = ActiveDocument.Range.Characters.Last Then Exit Sub
.Start = .Start + 1
.MoveStartUntil ".", wdForward
Loop
If ActiveDocument.Range.End - .Range.End < 750 Then
.End = ActiveDocument.Range.End
Exit Sub
End If
.End = .Start + 750
Do While Len(Replace(.Text, " ", "")) < 750
If .Characters.Last.Next = ActiveDocument.Range.Characters.Last Then Exit Sub
.End = .Start + 750 + Len(.Text) - Len(Replace(.Text, " ", ""))
Loop
Do While .Range.ComputeStatistics(wdStatisticCharacters) < 750
If .Characters.Last.Next = ActiveDocument.Range.Characters.Last Then Exit Sub
.End = .End + 1
Loop
End With
End Sub