Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #10  
Old 07-04-2022, 08:23 PM
Shmuel G Shmuel G is offline How do I convert a line of text to title case? Windows 10 How do I convert a line of text to title case? Office 2019
Novice
 
Join Date: Jul 2022
Posts: 3
Shmuel G is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Word's TitleCase function is a fairly blunt instrument that crudely capitalises the first letter of each word and destroys the capitalisation for acronyms and various surnames, for example. Such an approach really doesn't conform to the usual understanding title casing.
…………
To re-format just a selection, you could call the function with a macro like:
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
…………
This technique destroys any character formatting within the selection, such as change of fonts. Is there a simple way to replace the text of the range with the new version, while preserving the original formatting?
Reply With Quote
 

Tags
text conversion, title case



Similar Threads
Thread Thread Starter Forum Replies Last Post
creating a new TITLE property from text already within document smndnm Word VBA 6 07-04-2014 08:27 PM
Stop review query when small case at beginning of line dsrose Word 2 01-22-2014 12:19 AM
How do I 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
How do I convert a line of text to title case? Custom Text Filter for this particular case tinfanide Excel 2 09-13-2011 05:08 AM
How do I convert a line of text to title case? From all UPPER CASE to Proper Case davers Word 1 04-30-2009 12:41 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:57 PM.


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