Results 1 to 8 of 8

Thread: Help - macro to insert a return before each capital letter in selected text failing

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    VBAX Regular
    Joined
    Jan 2021
    Posts
    13
    Location
    Quote Originally Posted by June7 View Post
    I see nothing that inserts a carriage return/line feed.

    I doubt Word VBA is case sensitive by default. Most likely A=a.

    And if you did get the insert to work, what do you think would happen if text contains proper name?
    Thanks for your comment. I very much appreciate it.

    I'm a novice user of Word VBA, but as far as I know Word VBA can be case sensitive. If you again look at my code you should notice two things. Firstly, I am using wild chads to search for capitals: My understanding is [A-Z] stands for any capital letter. Secondly, I have set the Find parameter 'MatchWildcards' to 'True'.

    Here is an example of a vba search for capital letters using wild cards:

    Sub Demo()
    Dim fRng As Range
    With Selection.Find
      .ClearFormatting
      .Text = "[A-Z]{3}"
      .MatchWildcards = True
      .Wrap = wdFindContinue
      .Forward = True
      Do While .Execute = True
        Set fRng = ActiveDocument.Range(Start:=Selection.Start, End:=Selection.End)
        If Len(fRng.Words(1)) > 4 And fRng.Words(1).Case = 1 Then _
          fRng.Words(1).Font.Color = wdColorDarkRed
      Loop
    End With
    Set fRng = Nothing
    End Sub
    Source: https://stackoverflow.com/questions/...er-in-word-vba

    My problem is that I don't have enough knowledge of Word VBA to get my macro to work.

    Thanks again for your comments. I very much appreciate them.
    Last edited by Aussiebear; 11-15-2022 at 12:36 PM. Reason: Added code tags to supplied code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •