Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-06-2019, 02:44 PM
jeffreybrown jeffreybrown is offline VBA to convert a line of text to title case Windows 10 VBA to convert a line of text to title case Office 2016
Expert
VBA to convert a line of text to title case
 
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, 8 views)
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to convert a line of text to title case How do I convert a line of text to title case? neilfxb Word 21 02-22-2023 12:47 PM
Macro that formats (true title) case by Heading style Marrick13 Word VBA 13 09-20-2015 06:29 PM
VBA to convert a line of text to title case Customising a style that uses Title Case formatting Madanjeet Word 6 05-18-2015 10:11 AM
Stop review query when small case at beginning of line dsrose Word 2 01-22-2014 12:19 AM
VBA to convert a line of text to title case True Title Case for First Row of All Tables Marrick13 Word VBA 14 12-11-2013 09:12 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:50 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft