none
word macro RRS feed

  • Question

  • 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? 
    Saturday, May 6, 2017 11:28 PM

All replies

  • 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

    Sunday, May 7, 2017 12:33 AM
  • 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


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Monday, May 8, 2017 4:20 AM