View Single Post
 
Old 09-06-2019, 02:44 PM
jeffreybrown jeffreybrown is offline Windows 10 Office 2016
Expert
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

No worries Greg. Thanks for the follow-up.

@Paul,

I suppose I'm still doing something wrong here. I placed that bit of text after the line:
With Selection.Range, but it only fixes the last entry in the selection. I stepped thru the code and can see it looping, but it doesn't loop one paragraph at a time.

Code:
Sub MakeTitle()
    Application.ScreenUpdating = False
    Dim StrTmp As String
    With Selection.Range
        Do While InStr(.Text, Chr(151)) > 0
            .Start = .Start + InStr(.Text, Chr(151))
        Loop
            StrTmp = Trim(.Text)
        While Right(StrTmp, 1) = "."
            StrTmp = Left(StrTmp, Len(StrTmp) - 1)
        Wend
        While InStr(StrTmp, "  ") > 0
            StrTmp = Replace(StrTmp, "  ", " ")
        Wend
        StrTmp = TitleCase(StrTmp, bCaps:=False, bExcl:=True)
        .Text = StrTmp
    End With
    Application.ScreenUpdating = True
End Sub
I don't have any periods in these paragraphs so I would suppose the part in Red is not necessary?
Attached Files
File Type: docm TestFile.docm (26.3 KB, 6 views)
Reply With Quote