Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 09-04-2019, 08:38 AM
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 VBA to convert a line of text to title case

I found this link which seems in the right direction; however, looking to start the proper case change after an em dash. I know the change is required in the Blue sections of the code below, but not understanding how to change it. The part about looking for the period I don't even need as there are no periods in the sentence.

Before
AFMAN—AIR FORCE MANUAL
AO—ACTION OFFICER
CAF—CENTRAL ADJUDICATION FACILITY

AFTER
AFMAN—Air Force Manual


AO—Action Officer
CAF—Central Adjudication Facility

Code:
Sub MakeTitle()
    Application.ScreenUpdating = False
    Dim StrTmp As String
    With Selection.Range
      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:=False)
      .Text = StrTmp
    End With
    Application.ScreenUpdating = True
End Sub
Reply With Quote
 



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 10:08 AM.


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